Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed prop type: Component: prop type `props` is invalid;

I am getting warning as" Warning: Failed prop type: Component: prop type props is invalid; it must be a function, usually from the prop-types package, but received object"

my code is:

  const { history } = props.props
history.push('/next');

Component.propTypes = {
    props: {
        history: PropTypes.object,
    },
}

Component.defaultProps = {
    props: {
        history: PropTypes.object,
    },
}

My functionality working fine but getting this console error Can someone help me to resolve this warning?


1 Answers

You're using the value {} for props in propTypes, that's not allowed. You want shape:

Component.propTypes = {
  props: PropTypes.shape({
    history: PropTypes.object,
  }),
}
like image 170
Brandon Olivier Avatar answered Nov 27 '25 02:11

Brandon Olivier



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!