MCPcopy Index your code
hub / github.com/CSFrequency/react-firebase-hooks / useObjectVal

Function useObjectVal

database/useObject.ts:31–56  ·  view source on GitHub ↗
(
  query?: Query | null,
  options?: ValOptions<T>
)

Source from the content-addressed store, hash-verified

29};
30
31export const useObjectVal = <
32 T,
33 KeyField extends string = '',
34 RefField extends string = ''
35>(
36 query?: Query | null,
37 options?: ValOptions<T>
38): ObjectValHook<T, KeyField, RefField> => {
39 // Breaking this out in both `useList` and `useObject` rather than
40 // within the `snapshotToData` prevents the developer needing to ensure
41 // that `options` is memoized. If `options` was passed directly then it
42 // would cause the values to be recalculated every time the whole
43 // `options object changed
44 const { keyField, refField, transform } = options ?? {};
45
46 const [snapshot, loading, error] = useObject(query);
47 const value = useMemo(
48 () =>
49 (snapshot
50 ? snapshotToData(snapshot, keyField, refField, transform)
51 : undefined) as Val<T, KeyField, RefField>,
52 [snapshot, keyField, refField, transform]
53 );
54
55 return [value, loading, error];
56};

Callers

nothing calls this directly

Calls 2

snapshotToDataFunction · 0.90
useObjectFunction · 0.85

Tested by

no test coverage detected