Last active
May 6, 2020 10:29
-
-
Save abegehr/b6a8bec58563dd38f6c3c9d0b340092e to your computer and use it in GitHub Desktop.
Promise async, await, try, catch Example
This file contains hidden or 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 | |
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