Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enabling Firestore Persistence for React Native

I am using React Native Firebase and I am trying to enable persistence for my app.

On my Android onCreate:

public void onCreate() {
    super.onCreate();
    FirebaseDatabase.getInstance().setPersistenceEnabled(true);
    SoLoader.init(this, /* native exopackage */ false);
  }

For some reason when I am online and I kill my app and reopen, the images seems to reload and it takes long to appear..If I turn the net off they will come up instantly showing that the offline data actually works.

How do I enable the persistence for the firestore so it will load the unchanged data from the cache instantly?

I saw the documentation which shows that I would need to add this code for the android:

FirebaseFirestoreSettings settings = new FirebaseFirestoreSettings.Builder()
        .setPersistenceEnabled(true)
        .build();
db.setFirestoreSettings(settings);

but I have no idea how to integrate with the React Native Firebase as I am importing the RNFirebaseFirestorePackage

Any help would be appreciated!

like image 802
AlwaysConfused Avatar asked Jun 25 '18 15:06

AlwaysConfused


People also ask

How do I use firestore database in react native?

import firestore from '@react-native-firebase/firestore'; const usersCollection = firestore(). collection('Users'); The collection method returns a CollectionReference class, which provides properties and methods to query and fetch the data from Cloud Firestore.

Can't reach cloud firestore backend react native?

This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.

Is Firebase persistent?

Note that Firebase Auth web sessions are single host origin and will be persisted for a single domain only. Indicates that the state will only persist in the current session or tab, and will be cleared when the tab or window in which the user authenticated is closed.


1 Answers

For react-native+firebase, one of my suggestion would be react-native-firebase which is bridging between JS and native framework.

Doing quick search, seems like you cannot directly - enable persistance.

You need to do it through Settings.

like image 54
snjmhj Avatar answered Sep 23 '22 04:09

snjmhj