I want to pass a prop to a React Component, conditional to a boolean in parent component's state, The component expects to have myProp as an object, the propTypes conflagration is bellow:
//component's code
class MyComponent extends Component {
...
static propTypes = {
myProp: propTypes.object
}
...
}
Now, I am on to pass the prop like below:
//Parent component's code
class ParentComponent extends Component {
constructor() {
super();
this.state = {
par: true,
}
}
render(){
const obj = {
key1: 'value1',
key2: 'value2'
}
...
return (
<MyComponent
myProp = {this.state.par && obj}
/>
)
}
...
}
Executing the above code it gives me following warning in browser console:
Warning: Failed prop type: Invalid prop
myPropof typebooleansupplied toMyComponent, expectedobject.