This.setstate will unmount in callback
In fact, this is confused. I updated for React Router 4 which required a few changes and now when my server side registration errors return a console error:
setState (...): Can only update mounted or mounted component. This usually means that you called setState () on an unmounted component. This is a no-op. Check the code for the RegisterForm component.
What's really confusing is if I run this.setState({ errors: {createUserError: "Test error" }});
outside of the function Accounts.createUser
, I don't get the console error.
Any suggestions????
handleSubmit(event) {
event.preventDefault();
this.setState({errors: {} }, function() {
var data = {
email: this.state.email,
password: this.state.password
};
Accounts.createUser(data, (error) => { // This arrow function preserves this
if(error) {
this.setState({ errors: {createUserError: error.reason }});
}
});
});
}
+2
source to share