How can I send string data to firebase in background each 50 seconds

70 Views Asked by At

I am using counter that increases by 1 every 5 seconds and I want to store its value in firestore. I need a way to send the data in background and I want you to tell me the best practise to send the counter value and fetch it ? in which lifecycle part should I use the method? thank you all and I hope you understand my question.

1

There are 1 best solutions below

2
On

If you know that the counter increases by 1 every 5 seconds, there is no need to update the document every 5 seconds. All you need is to store is the moment the counter started, as everything else can be derived from that on the client.

For an example of how to implement such a distributed timer, see How to implement a distributed countdown timer in Firebase. While this question is using Firebase's other database, the same approach can be applied to Firestore.