React: checker is not a function

前端 未结 12 1414
庸人自扰
庸人自扰 2021-02-04 23:25

I\'m getting this weird warning message in the console for my React app.

Warning: Failed propType: checker is not a function Check the render method of <

12条回答
  •  被撕碎了的回忆
    2021-02-04 23:47

    The real explanation behind this issue is that react expects a PropType which is technically a function, aka checker. Examples for checker functions are:

    PropTypes.array
    PropTypes.shape({...})
    PropTypes.bool
    

    You got the idea... So what happens here is whenever you pass in something which isn't a checker, for example an undefined, react won't know what to do with this and so will complain:

    checker is not a function

    In my case, the cause was misspelling of the checker functions:

    PropTypes.shape({
        cats: PropTypes.Array // this is undefined
    })
    

    The correct version should be:

    PropTypes.shape({
        cats: PropTypes.array // lowercase is correct!
    })
    

提交回复
热议问题