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 using on().
  • 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

Share:
11,826
Krishan DKM
Author by

Krishan DKM

Updated on July 10, 2022

Comments

  • Krishan DKM
    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
    Krishan DKM about 6 years
    Thank you so much.
  • Jordan Daniels
    Jordan Daniels about 6 years
    @KrishanDKM no problem! Can you please mark this as correct as well?
  • Zeeshan Ali
    Zeeshan Ali almost 4 years
    Rong mark dont click he was going Web Not a Android