Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

144
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda