CSFrequency/react-firebase-hooks

reload() doesn't update existing items with useCollectionOnce

ZakKa89 opened this issue · 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.

+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?