I have a component that expects one type of object or another. I've tried variations of this:
C.propTypes = {
foo: PropTypes.oneOf([
PropTypes.shape({
x: PropTypes.string
}).isRequired,
PropTypes.shape({
y: PropTypes.string
})
]).isRequired
};
<C foo={{y: 'text'}} />
The warning:
Warning: Failed propType: Invalid prop
fooof value[object Object]supplied toC, expected one of [null,null].
Is this a bug, limitation, or am I doing it wrong?
I think you want PropTypes.oneOfType. oneOf is basically an enum.
Oh darn, thanks.
No problem. You're not the first one to do that (and I'm willing to bet you won't be the last :) )
Life saver. Total Life saver. Thanks
Same here, I was super confused by the error message 馃憤
Most helpful comment
I think you want
PropTypes.oneOfType.oneOfis basically an enum.