Answer the question
In order to leave comments, you need to log in
How to change the code so that the error does not appear?
componentWillReceiveProps = nextProps => {
if(nextProps.auth.isAuthenticated){
this.props.history.push('/dashboard')
}
if(nextProps.errors){
this.setState({
errors: nextProps.errors
})
}
};
Answer the question
In order to leave comments, you need to log in
When the error
property arrives, you update the component in an endless loop. The componentWillReceiveProps method itself is not recommended for use.
It is not clear why you need to write each new property value in the state of the same name, if you can use it directly?
Decision:
static getDerivedStateFromProps(props, state) {
if (props.message) {
return { message: props.message };
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question