Created
May 6, 2020 10:30
-
-
Save abegehr/ff11cc0d5163e416a845126e1077c33e to your computer and use it in GitHub Desktop.
Fetching data from Firestore sequentially.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://firebase.google.com/docs/firestore/quickstart | |
var db = firebase.firestore(); | |
async function fetchArticle(articleId, authorId) { | |
try { | |
// get author and article docs sequentially | |
const authorSnap = await db.doc("authors/" + authorId).get(); | |
const articleSnap = await db.doc("articles/" + articleId).get(); | |
} | |
catch (err) {/* handle error */} | |
// extract data | |
const authorData = authorSnap.data(); | |
const articleData = articleSnap.data(); | |
// save to state | |
this.setState({authorData, articleData}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment