真的很困惑這裏。我更新了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