Answer the question
In order to leave comments, you need to log in
Why doesn't componentWillMount work?
I have such routing.
<Route path="entity" component={EntityForm} />
<Route path="entity/edit/:entity_id" component={EntityForm} />
componentWillMount() {
if(!isEmpty(this.props.params.entity_id)) {
this.props.loadEntityRequest(this.props.params.entity_id).then(() => {
this.setState({name: this.props.entity.name});
});
} else {
this.props.initEntity();
}
}
Answer the question
In order to leave comments, you need to log in
The thing is, React is "smart". It understands that the same component needs to be rendered and does not replace it.
In this case, you can get the new props in the componentWillReceiveProps method and do a setState() there.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question