Skip to content

Instantly share code, notes, and snippets.

@Verthon
Last active March 16, 2019 20:55
Show Gist options
  • Save Verthon/e94775ff459d929a4029be868bdb0c44 to your computer and use it in GitHub Desktop.
Save Verthon/e94775ff459d929a4029be868bdb0c44 to your computer and use it in GitHub Desktop.
Fixin async set state
//----------------First---------------------------
componentDidMount() {
const events = [];
firebase
.collection("events")
.get()
.then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
events.push(doc.data());
});
this.setState({
eventContainer: events
});
})
}
//==============Second=======================
componentDidMount() {
const events = [];
firebase
.collection("events")
.get()
.then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
events.push(doc.data());
});
})
.then(function() {
this.setState({
eventContainer: events
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment