【发布时间】:2018-01-29 14:29:39
【问题描述】:
这是我的componentDidMount 方法。我想设置当前用户的状态,然后在设置该用户时调用该函数。我该怎么做?
componentDidMount = () => {
firebase.auth().onAuthStateChanged((user) => {
if (user) {
this.setState({user: user})
}
});
this.props.retrieveMatches(this.state.user.uid)
}
我尝试过使用 async/await 但我在这里没有正确使用它:
async componentDidMount = () => {
await firebase.auth().onAuthStateChanged((user) => {
if (user) {
this.setState({user: user})
}
});
this.props.retrieveMatches(this.state.user.uid)
}
基本上我想在第 7 行调用 props 函数之前等待第 2-6 行
【问题讨论】:
标签: javascript reactjs asynchronous setstate