Search code examples
javascriptreactjsreact-propstypecheckingreact-proptypes

Typechecking with PropTypes gives me an error even though the props show properly


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 in NewChannel, but its value is undefined.

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.


Solution

  • 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.