React: checker is not a function

前端 未结 12 1405
庸人自扰
庸人自扰 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:37

    I too got this error on putting proptypes in wrong format:

    static propTypes = {
      workHard: PropTypes.func.isRequired,
      winBig: PropTypes.shape({
        prize: { // issue
          PENDING: PropTypes.bool,
        },
      }),
    };
    

    Turns out, prop types are expected to be either of type PropTypes.shape or PropTypes.objectOf when it comes to declaring object props

    So, error was fixed upon changing code to this:

    static propTypes = {
      workHard: PropTypes.func.isRequired,
      winBig: PropTypes.shape({
        prize: PropTypes.shape({
          SUCCESS: PropTypes.bool,
        }),
      }),
    };
    

提交回复
热议问题