I am type-checking my components with prop-types
, but even though I am getting the values properly in the right type, I still get the error message as following:
Warning: Failed prop type: The prop
id
is marked as required inNewChannel
, but its value isundefined
.
const NewChannel = props => {
const { id } = props.match.params
return(
//some logic
)
}
NewChannel.propTypes = {
id: PropTypes.string.isRequired
}
export default React.memo(NewChannel)
When I console.log
the props id
, it's not undefined.
You type checking says: props
will have an id field like: props.id
. But you are getting id from props.match.params
. That is why it is complaining.