Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

143
Views
Does Firebase Firestore keep a local copy of snapshot

I am using firebase firestore for my chat room application.

I have a function to send messages to firebase as

const sendMessageHandler = message => {
  if (message) {
    firestore()
      .collection(`ChatRooms/${roomId}/messages`)
      .doc(moment().format('YYYY-MM-DD-HH-mm-sssss'))
      .set({
        message: Encrypt(message),
        userId: userId,
      });
  }
};

and I am fetching messages into flatlist only from firestore as

// this messages const is getting data only from firestore
const [messages, setMessage] = useState([]);

firestore()
  .collection(`ChatRooms/${roomId}/messages`)
  .onSnapshot(
    querySnapshot => {
      const messages = [];
      querySnapshot.forEach(dataSnapshot => {
        messages.push({
          id: dataSnapshot.id,
          message: dataSnapshot.data().message,
          userId: dataSnapshot.data().userId,
        });
      });
      setMessage(messages.reverse());
      setLoading(false);
    },
    error => {
      console.log('error : ', error);
    },
  );


// And now I am using this messages somewhere in return function of a component as : 

<FlatList
  data={messages}
  renderItem={flatListItemRenderer}
  inverted={true}
/>

Notice I am fetching only from firestore and not locally.

Now I turned off the internet and tried sending messages so this happens

The data has not been updated to firestore (of course because of no internet), but the flatlist has been updated with the new message !!

The only possibility I can think of is that the setter methods of firestore is storing data in both local and remote database and the getter method is first getting snapshot from local database and then remote database.

So the question is does @react-native-firebase/firestore keep a local snapshot also and updates both local and remote snapshot of data whenever we change something?

Github Link

Edit :
Firestore docs says Firestore provides out of the box support for offline capabilities. When reading and writing data, Firestore uses a local database which synchronizes automatically with the server.This functionality is enabled by default, however it can be disabled if you need it to be disabled

I tried turning off persistence, but this property is related to storing data offline not the state. i.e, now when my app loads it fetch all the data directly from server(previously fetching from storage and server both), but the flatlist still updates with the new message(maybe it is storing some state like useState also???)

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The Firestore SDK keeps a local copy of:

  • All data that you have an active listener for.
  • All pending writes.

In addition, if offline persistence is enabled, it also keeps a local copy of data that your code has recently read.


When you make a write operation, the SDK:

  1. Writes your operation to its queue of pending writes.
  2. Fires an event for any local listeners.
  3. Tries to synchronize the pending write with the server.

Steps 1 and 2 always happen, regardless of whether you are online or offline. Only step 3 won't complete immediately when you are offline.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!