haktanyucel
haktanyucel

Reputation: 19

React-Native : Firebase Realtime Database How Can I Get One Data

I have this database. database

How can i get firstName in React-Native ?

Upvotes: 0

Views: 700

Answers (2)

Redmen Ishab
Redmen Ishab

Reputation: 2339

It's simple in your case : use react-native-firebase

import firebase from 'react-native-firebase'


 const ref = firebase.database().ref('users/fwDRY...G3');
 const name = ref.get({ firstname: 'firstname' });
 console.log(name.firstname)

Find yourself helpful from the docs: https://rnfirebase.io/docs/v5.x.x/database/reference/database

Upvotes: 2

damienix
damienix

Reputation: 6763

As React Native runs in Java Script thread on mobile platforms there are 2 ways to use it.

  1. Using Web SDK, but it might be slower and is not as well integrated to the mobile operating system as native.
  2. Using Native SDK for each platform. Using them manually on 2 platforms would require you to write React Native bindings for both platforms. Fortunately, the job has already been done. I highly recommend you to use this library https://github.com/invertase/react-native-firebase. It uses native APIs internally but exposes them into nice JavaScript API. It requires some setup but you won't work it around anyway regardless of the method chosen. For example, to set it up for Android, you need to follow

After you set it up, follow the link provided by frank-van-puffelen, https://firebase.google.com/docs/database/web/read-and-write#listen_for_value_events. The API on react-native-firebase is almost the same.

Upvotes: 1

Related Questions