Retrieve data from firebase in react native
11,826
I think the firebase docs are pretty good and give a good explanation of how to use it.
https://firebase.google.com/docs/database/web/read-and-write
To be short:
- once you have specified a reference, ex.
let users = firebase.database().ref('users/' + userId)
, you can read the data either once using the.once()
method or add a listener for changes in the data usingon()
. - You receive a snapshot from either of these methods, and need to call
snapshot.val()
to retrieve the data. - Simply assign the snapshot.val() to a variable declared outside of the reading method, and you're good to go.
You can also reference a simple project I made using React-Native and firebase here: https://github.com/liplylie/rnChallenge
![Krishan DKM](https://i.stack.imgur.com/C5Wdw.png?s=256&g=1)
Author by
Krishan DKM
Updated on July 10, 2022Comments
-
Krishan DKM almost 2 years
enter image description hereHow to retrieve data from firebase database and how to assign that values to variables in react native
How can I get these two values into variables using simple way.
-
Krishan DKM about 6 yearsThank you so much.
-
Jordan Daniels about 6 years@KrishanDKM no problem! Can you please mark this as correct as well?
-
Zeeshan Ali almost 4 yearsRong mark dont click he was going Web Not a Android