真的很困惑这里。我更新了React Router 4,它需要进行一些更改,现在当我的注册在服务器端出现错误时,它返回控制台错误: 这是回调。如何停止从卸载组件回调
setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the RegisterForm component.
什么是真正的困惑是,如果我跑this.setState({ errors: {createUserError: "Test error" }});
外Accounts.createUser
功能我没有得到consolde错误。
任何建议????
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 }});
}
});
});
}
[This.setstate在回调中卸载]的副本(https://stackoverflow.com/questions/44150077/this-setstate-unmounts-within-a-callback)。请不要重复发布。 – MasterAM