Skip to content
Advertisement

How to get info from firebase firestore database in react-native

I am trying to get the logged-in user info from my firestore database in my react native app.

I am new to react native, therefore I don’t know the correct syntax or methodology to do these things with firestore.

I’ve read many documentations but they don’t provide information for every situation and instance.

here is my code:

my AuthProvider.js:

JavaScript

my profileScreen.js:

JavaScript

How can I fetch a single user’s information, or in general how can I fetch information from firestore with react-native?

UPDATE:

i tried this following code, but in the console i get undefined for the name. why is that?

JavaScript

Advertisement

Answer

You could try the following:

JavaScript

Depending on what you get and what are you using. For example, if you want to fetch the data you will have a collection of all users, in which each document will be a different user/id. And to get the data of the current authenticated user, you can use firebase.auth().currentUser.uid(replace it with the “DOC_NAME” in the code above).

For example, to display a greeting message to a specific logged in user, you will have to use useState from rn.

JavaScript

then write that function

JavaScript

And then, in your component, you can display user name, email, age etc, depending on your field.

For example, if your user has a field “name” with name on it, you can display it like this:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement