Created
March 13, 2021 00:32
-
-
Save yhdesai/e37274de3af07e2c3f88209ff3b8af3e to your computer and use it in GitHub Desktop.
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
| //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