React: checker is not a function

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

    In my case, I was validating props wrong. I forgot to wrap the profile object into PropTypes shape method.

    Mistake

    Component.propTypes = {
      viewProfile: PropTypes.shape({
        profile: {     // it is a normal object without a PropTypes shape method
          firstName: PropTypes.string,
          lastName: PropTypes.string,
          profileImage: PropTypes.string,
        },
      }).isRequired,
    };
    

    Solution

    Component.propTypes = {
      viewProfile: PropTypes.shape({
        profile: PropTypes.shape({
          firstName: PropTypes.string,
          lastName: PropTypes.string,
          profileImage: PropTypes.string,
        }),
      }).isRequired,
    };
    

提交回复
热议问题