CSFrequency / react-firebase-hooks

React Hooks for Firebase.
Apache License 2.0
3.55k stars 304 forks source link

add enabled flag for firestore #260

Closed hussamkhatib closed 1 year ago

hussamkhatib commented 1 year ago

fetch only if enabled is true,

Coinsider the example

  const [value, loading, error] = useDocument(
    doc(firestore, "users", useruid)
  );

adding a optional flag to fetch only when useruid is defined

  const [value, loading, error] = useDocument(
    doc(firestore, "users", useruid),
    {
      enabled: useruid,   // make a network request if only Boolean(useruid)  is true
    }
  );

If required, I am willing to contribute

kaueDM commented 1 year ago

110

chrisbianca commented 1 year ago

@hussamkhatib As per #110, the approach used by this library is to support the passing of null / undefined to the hook to prevent loading