It appears that first time when the component loads or get called your are passing it some value which is undefined initially and later becomes available. For example lets say you have a parent component as following
class Parent extends React.Component {
constructor() {
this.state = {0}
}
render() {
<Child value={this.state.value} />
}
}
As you can see, initially the state doesn't have a property value
so the Child
will receive undefined
for this.props.value
. It will only receive not undefined
when some parent function changes it like this,
class Parent extends React.Component {
constructor() {
this.state = {0}
}
onAction() {
this.setState({value: true})
}
render() {
<Child value={this.state.value} />
}
}
So if on some event parent calls its OnAction
it will change the state and Child will get this.props.value
as true
but as Child will be already rendered componentWillMount
hook will not get triggered but componentWillReceiveProps
will. So if you want to use the prop in componentWillMount
make sure its passed at the first render of the child and if that is not possible use componentWillReceiveProps
to process the props