Skip to content

Instantly share code, notes, and snippets.

@abegehr
Last active May 6, 2020 10:29
Show Gist options
  • Save abegehr/b6a8bec58563dd38f6c3c9d0b340092e to your computer and use it in GitHub Desktop.
Save abegehr/b6a8bec58563dd38f6c3c9d0b340092e to your computer and use it in GitHub Desktop.
Promise async, await, try, catch Example
// https://firebase.google.com/docs/firestore/quickstart
async function main() {
try {
const doc = await db.doc("user/" + uid).get()
if (doc.exists) {
console.log("User data:", doc.data());
// use fetched data, for example in setState()
} else {
console.warn("No user data.");
}
}
catch(error) {
console.log("Error getting user data:", error);
}
}
// ...
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment