React: checker is not a function

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

    In my case I got this when I used the shape function with a complex object. The solution was to go from:

    outerObject: shape({
      firstInnerObject: {
        a: string,
        b: string,
      },
      secondInnerObject: {
        a: string,
        b: number,
      },
    }),
    

    To:

    outerObject: shape({
      firstInnerObejct: shape({
        a: string,
        b: string,
      }),
      secondInnerObject: shape({
        a: string,
        b: number,
      }),
    }),
    

    Very trivial, I know, yet this might be the solution for someone equally inexperienced as I am. ;)

    0 讨论(0)
  • 2021-02-04 23:33

    FWIW, I was getting Failed PropType: typeChecker is not a function. I noticed that in my PropTypes.arrayOf() properties, I was passing in an object of PropTypes e.g. PropTypes.arrayOf({})instead of passing in PropTypes.shape() e.g. PropTypes.arrayOf(PropTypes.shape({})

    Making this change eliminated the error message.

    0 讨论(0)
  • 2021-02-04 23:33

    In my case I'd simply accidentally removed a type:

    grValue: PropTypes, // instead of PropTypes.string
    
    0 讨论(0)
  • 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,
        }),
      }),
    };
    
    0 讨论(0)
  • 2021-02-04 23:39

    A pull request has been merged to the React repo that provides a better feedback for the developer whenever a mistake like this happens again.

    Now, the validation message will look like the following:

    Invalid argument supplied to oneOf, expected an instance of array.

    https://github.com/facebook/react/pull/3963

    This should be part of React 0.14.

    0 讨论(0)
  • 2021-02-04 23:40

    My version of Warning: Failed propType: checker is not a function came from forgetting to use PropTypes.shape for an object.

    Changing:

    someProps: {
        prop: React.PropTypes.string,
        anotherProp: React.PropTypes.number,
    }
    

    to this fixed the problem:

    someProps: React.PropTypes.shape({
        prop: React.PropTypes.string,
        anotherProp: React.PropTypes.number,
    })
    
    0 讨论(0)
提交回复
热议问题