MCPcopy Create free account
hub / github.com/CSFrequency/react-firebase-hooks / useCollection

Function useCollection

firestore/useCollection.ts:29–59  ·  view source on GitHub ↗
(
  query?: Query<T> | null,
  options?: Options
)

Source from the content-addressed store, hash-verified

27} from './types';
28
29export const useCollection = <T = DocumentData>(
30 query?: Query<T> | null,
31 options?: Options
32): CollectionHook<T> => {
33 const { error, loading, reset, setError, setValue, value } = useLoadingValue<
34 QuerySnapshot<T>,
35 FirestoreError
36 >();
37 const ref = useIsFirestoreQueryEqual<Query<T>>(query, reset);
38
39 useEffect(() => {
40 if (!ref.current) {
41 setValue(undefined);
42 return;
43 }
44 const unsubscribe = options?.snapshotListenOptions
45 ? onSnapshot(
46 ref.current,
47 options.snapshotListenOptions,
48 setValue,
49 setError
50 )
51 : onSnapshot(ref.current, setValue, setError);
52
53 return () => {
54 unsubscribe();
55 };
56 }, [ref.current]);
57
58 return [value as QuerySnapshot<T>, loading, error];
59};
60
61export const useCollectionOnce = <T = DocumentData>(
62 query?: Query<T> | null,

Callers 1

useCollectionDataFunction · 0.85

Calls 2

useIsFirestoreQueryEqualFunction · 0.90
setValueFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…