Search code examples
firebasereact-nativereact-native-firebase

Firebase support confirmation for react-native apps


I am building an application that has a requirement of using a firebase realtime database. I tried using this library but facing some issues. Can someone please confirm if react-native supports firebase totally or it supports with some known bugs.

Issue:

  1. I created a react-native app. Now what I want is to stop the synchronization of the realtime database from the react-native application. So I used the property which is " keepSynced(false)" but it's not working as the expected behavior mentioned in the rnfirebase library. Also, there is another method named "setPersistenceEnabled(true)", this method is expected to return Promise but it is not doing so.
  2. Need confirmation if this is a known bug and if there are some limitations in using firebase for react-native applications

Below are my lines of code:

const reference = database().ref('/');
reference.keepSynced(false);

database().setPersistenceEnabled(true).then() ; // not working as expected, Promise type return is not working.

Solution

  • By default, Firebase will only synchronize a node from the server while you have a listener attached to that node. Setting keepSynced(true) on a node, ensures that node also gets synchronized when no listener is attached. Setting keepSynced(true) on a node simply resets it to its default state of only synchronizing data when there's an active listener on the node.

    There is no way to not keep a node synchronized when you have a listener attached to it.


    By default Firebase keeps an in-memory model of any data it is currently monitoring. When you call setPersistenceEnabled(true), this in-memory model is also written to disk, and kept up to date there. I'm not really sure why this call returns a Promise, as the native methods (like here in Android) do not return anything.