Javascript React/Firebase用户注册承诺-Can';t在未安装的组件上调用setState
我正在尝试这样做:Javascript React/Firebase用户注册承诺-Can';t在未安装的组件上调用setState,javascript,reactjs,firebase,firebase-authentication,Javascript,Reactjs,Firebase,Firebase Authentication,我正在尝试这样做: firebase.auth() .createUserWithEmailAndPassword(this.state.email, this.state.password) .then( data => { const {user} = data; if (user) { user.updateProfile({displayName: name}) .then(() =&g
firebase.auth()
.createUserWithEmailAndPassword(this.state.email, this.state.password)
.then( data => {
const {user} = data;
if (user) {
user.updateProfile({displayName: name})
.then(() => {
// when i try to change state for reload, it says its unmounted??
this.forceUpdate()
})
}
})
.catch((error) => {
this.setState({errors: error.message})
})
其中,在创建用户后,它还会更新其displayName。我想强制刷新/状态更改,因为有一个组件正在等待displayName。但是,它给了我一个错误无法在未安装的组件上调用setState…
有人能解释错误的原因吗?最好的处理方法是什么
编辑。当用户提交注册表单时会调用此代码您在哪里调用此代码?在卸载组件时您没有取消请求,请查看您是否尝试使用状态重新呈现而不是强制呈现?@Anthony我在用户提交注册时调用此代码form@joseluismurillorios是的,我也试过设置状态,但是我得到了同样的错误,你在哪里调用这个代码?当组件卸载时,你没有取消你的请求,看看你是否尝试过使用状态重新渲染而不是强制渲染?@Anthony我在用户提交注册时调用这个form@joseluismurillorios是的,我也试过设置状态,但是我得到了同样的错误