( query?: Query | null, options?: ValOptions<T> )
| 29 | }; |
| 30 | |
| 31 | export 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 | }; |
nothing calls this directly
no test coverage detected