I have a login page in which I use componentWillReceiveProps to go to the next page. But the state that I set inside componentWillReceiveProps does not seem to be set.
This is my componentWillReceiveProps method:
componentWillReceiveProps(nextProps) { if (nextProps.isAuthenticated === true) { browserHistory.push('/home'); } else { console.log("this.props :::" + JSON.stringify(this.props)) console.log("this.state :::" + JSON.stringify(this.state)) console.log("nextProps :::" + JSON.stringify(nextProps)) this.setState({ errorMessage: nextProps.authenticationError }) console.log("this.state :::" + JSON.stringify(this.state)) } }
console output I get this:
this.props :::{"authenticationError":null} this.state :::{"username":"35135","password":"3135","errorMessage":""} nextProps :::{"isAuthenticated":false,"authenticationError":"Could not find user in DB."} this.state :::{"username":"35135","password":"3135","errorMessage":""}
Here, even after setting the state, my state has not changed.
Please tell me what I'm doing wrong.
EDIT: I have this component, which is ErrorText , which accepts the errroMessage property.
<ErrorText errorMsg={this.state.errorMessage}></ErrorText>
source share