To pass the initial state while rendering a component with React, we set the prop value as the value of the state’s initial value in getInitialState
.
For instance, we write
class C extends Component {
//...
getInitialState() {
return { foo: this.props.foo };
}
//...
}
to set the initial value of the foo
state to the foo
prop’s value.