This is my componentDidMount
method. I want to set the state of the current user and then call the function when that user is set. How can I do this?
componentDidMount = () => {
firebase.auth().onAuthStateChanged((user) => {
if (user) {
this.setState({user: user})
}
});
this.props.retrieveMatches(this.state.user.uid)
}
I've tried using async/await but im not using it correctly here:
async componentDidMount = () => {
await firebase.auth().onAuthStateChanged((user) => {
if (user) {
this.setState({user: user})
}
});
this.props.retrieveMatches(this.state.user.uid)
}
basically I want to await for lines 2-6 before calling the props function on line 7
you need to use .setState()
's callback function:
componentDidMount = () => {
firebase.auth().onAuthStateChanged((user) => {
if (user) {
this.setState({user: user}, () => {
this.props.retrieveMatches(this.state.user.uid);
})
}
});
}
greetings
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With