Skip to content

Instantly share code, notes, and snippets.

@yhdesai
Created March 13, 2021 00:32
Show Gist options
  • Save yhdesai/e37274de3af07e2c3f88209ff3b8af3e to your computer and use it in GitHub Desktop.
Save yhdesai/e37274de3af07e2c3f88209ff3b8af3e to your computer and use it in GitHub Desktop.
//If functional component, const [cityData, setCityData] = useState[]
//Firebase, Getting a single document
var docRef = db.collection("cities").doc("SF");
docRef.get().then((doc) => {
if (doc.exists) {
console.log("Document data:", doc.data());
this.setState({cityData: doc.data()}); //OR(if functional component) setCityData(doc.data());
} else {
// doc.data() will be undefined in this case
console.log("No such document!");
}
}).catch((error) => {
console.log("Error getting document:", error);
});
...
return(
...
<h1>{this.state.cityData.[node] //OR cityData
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment