File tree Expand file tree Collapse file tree 2 files changed +39
-6
lines changed Expand file tree Collapse file tree 2 files changed +39
-6
lines changed Original file line number Diff line number Diff line change @@ -66,7 +66,7 @@ const useCollectionInternal = <T = DocumentData>(
66
66
return ;
67
67
}
68
68
if ( listen ) {
69
- const listener = options ?. snapshotListenOptions
69
+ const unsubscribe = options ?. snapshotListenOptions
70
70
? onSnapshot (
71
71
ref . current ,
72
72
options . snapshotListenOptions ,
@@ -76,11 +76,28 @@ const useCollectionInternal = <T = DocumentData>(
76
76
: onSnapshot ( ref . current , setValue , setError ) ;
77
77
78
78
return ( ) => {
79
- listener ( ) ;
79
+ unsubscribe ( ) ;
80
80
} ;
81
81
} else {
82
+ let effectActive = true ;
83
+
82
84
const get = getDocsFnFromGetOptions ( options ?. getOptions ) ;
83
- get ( ref . current ) . then ( setValue ) . catch ( setError ) ;
85
+
86
+ get ( ref . current )
87
+ . then ( ( result ) => {
88
+ if ( effectActive ) {
89
+ setValue ( result ) ;
90
+ }
91
+ } )
92
+ . catch ( ( error ) => {
93
+ if ( effectActive ) {
94
+ setError ( error ) ;
95
+ }
96
+ } ) ;
97
+
98
+ return ( ) => {
99
+ effectActive = false ;
100
+ } ;
84
101
}
85
102
} , [ ref . current ] ) ;
86
103
Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ const useDocumentInternal = <T = DocumentData>(
65
65
return ;
66
66
}
67
67
if ( listen ) {
68
- const listener = options ?. snapshotListenOptions
68
+ const unsubscribe = options ?. snapshotListenOptions
69
69
? onSnapshot (
70
70
ref . current ,
71
71
options . snapshotListenOptions ,
@@ -75,12 +75,28 @@ const useDocumentInternal = <T = DocumentData>(
75
75
: onSnapshot ( ref . current , setValue , setError ) ;
76
76
77
77
return ( ) => {
78
- listener ( ) ;
78
+ unsubscribe ( ) ;
79
79
} ;
80
80
} else {
81
+ let effectActive = true ;
82
+
81
83
const get = getDocFnFromGetOptions ( options ?. getOptions ) ;
82
84
83
- get ( ref . current ) . then ( setValue ) . catch ( setError ) ;
85
+ get ( ref . current )
86
+ . then ( ( doc ) => {
87
+ if ( effectActive ) {
88
+ setValue ( doc ) ;
89
+ }
90
+ } )
91
+ . catch ( ( error ) => {
92
+ if ( effectActive ) {
93
+ setError ( error ) ;
94
+ }
95
+ } ) ;
96
+
97
+ return ( ) => {
98
+ effectActive = false ;
99
+ } ;
84
100
}
85
101
} , [ ref . current ] ) ;
86
102
You can’t perform that action at this time.
0 commit comments