Setstate Doesn't Update The State Array
A user clicks the button, onClick I make an ajax post request and I'm trying to setState in my .then() and .catch() phases of my request. I keep getting 'Can only update a mounted
Solution 1:
You should not mutate the state directly.
handleSuccess(response) {
console.log(response);
this.props.setLoading(false);
if (this._mounted) {
this.setState({formSubmitted: true, formSuccess: true});
}
},
handlError(error) {
console.log("error")
this.props.setLoading(false);
if (this._mounted) {
this.setState({formSubmitted: true, formSuccess: true});
}
console.log(error);
},
Post a Comment for "Setstate Doesn't Update The State Array"