I am using the getCountFromServer()
for my React App to display the number of docs in a collection.
However, when the user deletes a doc on the front end or creates one, the count is not updated in real-time.
Is it possible to fix this or must the user always reload the page to see the latest data?
2
Answers
The documentation says, emphasis mine:
So, no, you can’t get realtime count updates. You will have to make the request again to get an update. Whether or not you require a page refresh is up to you.
If you are using
getCountFromServer()
to load the initial count and then want to decrement it for all active users when a document is deleted, you can use a listener on the same collection and update the state on frontend like this:This way you won’t have to calculate the count again or maintain the count anywhere.