reactjsreact-reduxreactive-programmingreact-proptypes

Failed prop type: Invalid prop of type `function` supplied expected a single ReactElement


I'm trying to make a post using react v4 and axios, I was following this tutorial and I did exactly as he said, but I'm getting an error: Maybe because I'm using another version of react, how can fix it?

Failed prop type: Invalid prop userSignupRequest of type function supplied to SignUp, expected a single ReactElement.

here is my code:

import React from 'react';
import SignUpForm from './SignUpForm';
import { connect } from 'react-redux';
import { userSignupRequest } from '../../actions/signupActions';
import PropTypes from 'prop-types';

class SignUp extends React.Component{
  render(){
    const { userSignupRequest } = this.props;
    return(
        <SignUpForm userSignupRequest={userSignupRequest}/>
    );
  }
}


SignUp.propTypes = {
  userSignupRequest: PropTypes.element.isRequired
}

export default connect(null, { userSignupRequest })(SignUp);

SignUp Actions:

import axios from 'axios';
import Constants from '../components/Constants'

export function userSignupRequest(userData) {
  return dispatch => {
    return axios.post(Constants.URL_REGISTER, userData);
  }
}

Solution

  • Did you mean to have have element instead of func in your PropTypes?

    SignUp.propTypes = {
      userSignupRequest: PropTypes.func.isRequired
    }