React: checker is not a function
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.
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. ;)
Change
React.PropTypes.oneOfType(React.PropTypes.number, React.PropTypes.object)
to
React.PropTypes.oneOfType([React.PropTypes.number, React.PropTypes.object])
(the argument should be an array)
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,
};