11import firebase from 'firebase/app' ;
2- import { useEffect } from 'react' ;
2+ import { useEffect , useMemo } from 'react' ;
33import { snapshotToData } from './helpers' ;
44import { LoadingHook , useIsEqualRef , useLoadingValue } from '../util' ;
55
@@ -32,7 +32,11 @@ export const useDocumentOnce = (
3232 . catch ( setError ) ;
3333 } , [ ref . current ] ) ;
3434
35- return [ value , loading , error ] ;
35+ const resArray : DocumentOnceHook = [ value , loading , error ]
36+ return useMemo (
37+ ( ) => resArray ,
38+ resArray ,
39+ ) ;
3640} ;
3741
3842export const useDocumentDataOnce = < T > (
@@ -44,10 +48,15 @@ export const useDocumentDataOnce = <T>(
4448) : DocumentDataOnceHook < T > => {
4549 const idField = options ? options . idField : undefined ;
4650 const getOptions = options ? options . getOptions : undefined ;
47- const [ value , loading , error ] = useDocumentOnce ( docRef , { getOptions } ) ;
48- return [
49- ( value ? snapshotToData ( value , idField ) : undefined ) as T ,
50- loading ,
51- error ,
52- ] ;
51+ const [ snapshot , loading , error ] = useDocumentOnce ( docRef , { getOptions } ) ;
52+ const value = useMemo (
53+ ( ) => ( snapshot ? snapshotToData ( snapshot , idField ) : undefined ) as T ,
54+ [ snapshot , idField ]
55+ ) ;
56+
57+ const resArray : DocumentDataOnceHook < T > = [ value , loading , error ]
58+ return useMemo (
59+ ( ) => resArray ,
60+ resArray ,
61+ ) ;
5362} ;
0 commit comments