nandorojo / swr-firestore

Implement Vercel's useSWR for querying Firestore in React/React Native/Expo apps. 👩‍🚒🔥
MIT License
777 stars 65 forks source link

`useCollection` does not fetch on mount #110

Closed sarimabbas closed 3 years ago

sarimabbas commented 3 years ago

Hello, thank you for this lib!

I am running into some strange behavior where useCollection returns an empty array on mount (but fetches successfully on subsequent renders or when calling revalidate).

My dependencies:

    "firebase": "^8.3.2",
    "@nandorojo/swr-firestore": "^0.16.0",

My code:

const Sidebar = () => {

  const uid = fuego.auth().currentUser?.uid;

  const { data: folders, revalidate } = useCollection<Folder>(
    !!uid ? "folders" : null,
    {
      where: ["userId", "==", uid],
    }
  );

  // revalidating after mount seems to work
  // useEffect(() => {
  //   setTimeout(() => {
  //     revalidate();
  //   }, 2000);
  // }, [uid]);

   return <FolderTree folders={folders}/>
}

I would appreciate any insight or help in this matter. Thank you!

nandorojo commented 3 years ago

Weird, could you reproduce on codesandbox?

sarimabbas commented 3 years ago

I have tried but not been able to produce deterministically on CodeSandbox. I am using a workaround where I revalidate after mount and that seems to work fine. So I will close this issue for now. Thank you for your help!

345ml commented 3 years ago

@nandorojo https://swr.vercel.app/docs/conditional-fetching In my environment, this problem occurs when I use Conditional Fetching.

345ml commented 3 years ago

I have tried but not been able to produce deterministically on CodeSandbox. I am using a workaround where I revalidate after mount and that seems to work fine. So I will close this issue for now. Thank you for your help!

@sarimabbas I can't get the data to refresh on Android, did it work in your environment?