react-firebase-hooks icon indicating copy to clipboard operation
react-firebase-hooks copied to clipboard

reload() doesn't update existing items with useCollectionOnce

Open ZakKa89 opened this issue 2 years ago • 2 comments

I'm guessing this is more of a cache issue with firebase than the library. But I was wondering if somebody bumped into the same issue and has a solution.

The issue

if you update an item in a collection, and use the reload() function to refetch, the item will not not be updated. The refetch is only useful in adding or deleting items.

Possible workarounds

  • manually optimistically updating the state myself.
  • Turning on realtime data again, but my client doesn't want this.

ZakKa89 avatar Apr 19 '23 23:04 ZakKa89

+1 on this. reload() is so misleading.

The work around for me unfortunately was to just use the firebase sdk directly after update:

try {
  await updateDoc(singleDocRef, {
    ffo: 'bar'
  });
  const mySnap = await getDocs(mySnapRef);
  const myData = mySnap.docs.map(d => d.data());

  // Look at myData, not your open web socket data
} catch(e) {
}

If that works, can we conclude the issue lies with react-firebase-hooks and this is an actual bug with the library?

ZakKa89 avatar Oct 27 '24 08:10 ZakKa89