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 @@ -75,7 +75,7 @@ const useCollectionInternal = <T = DocumentData>(
75
75
return ;
76
76
}
77
77
if ( listen ) {
78
- const listener =
78
+ const unsubscribe =
79
79
options && options . snapshotListenOptions
80
80
? onSnapshot (
81
81
ref . current ,
@@ -86,13 +86,30 @@ const useCollectionInternal = <T = DocumentData>(
86
86
: onSnapshot ( ref . current , setValue , setError ) ;
87
87
88
88
return ( ) => {
89
- listener ( ) ;
89
+ unsubscribe ( ) ;
90
90
} ;
91
91
} else {
92
+ let effectActive = true ;
93
+
92
94
const get = getDocsFnFromGetOptions (
93
95
options ? options . getOptions : undefined
94
96
) ;
95
- get ( ref . current ) . then ( setValue ) . catch ( setError ) ;
97
+
98
+ get ( ref . current )
99
+ . then ( ( result ) => {
100
+ if ( effectActive ) {
101
+ setValue ( result ) ;
102
+ }
103
+ } )
104
+ . catch ( ( error ) => {
105
+ if ( effectActive ) {
106
+ setError ( error ) ;
107
+ }
108
+ } ) ;
109
+
110
+ return ( ) => {
111
+ effectActive = false ;
112
+ } ;
96
113
}
97
114
} , [ ref . current ] ) ;
98
115
Original file line number Diff line number Diff line change @@ -74,7 +74,7 @@ const useDocumentInternal = <T = DocumentData>(
74
74
return ;
75
75
}
76
76
if ( listen ) {
77
- const listener =
77
+ const unsubscribe =
78
78
options && options . snapshotListenOptions
79
79
? onSnapshot (
80
80
ref . current ,
@@ -85,14 +85,30 @@ const useDocumentInternal = <T = DocumentData>(
85
85
: onSnapshot ( ref . current , setValue , setError ) ;
86
86
87
87
return ( ) => {
88
- listener ( ) ;
88
+ unsubscribe ( ) ;
89
89
} ;
90
90
} else {
91
+ let effectActive = true ;
92
+
91
93
const get = getDocFnFromGetOptions (
92
94
options ? options . getOptions : undefined
93
95
) ;
94
96
95
- get ( ref . current ) . then ( setValue ) . catch ( setError ) ;
97
+ get ( ref . current )
98
+ . then ( ( doc ) => {
99
+ if ( effectActive ) {
100
+ setValue ( doc ) ;
101
+ }
102
+ } )
103
+ . catch ( ( error ) => {
104
+ if ( effectActive ) {
105
+ setError ( error ) ;
106
+ }
107
+ } ) ;
108
+
109
+ return ( ) => {
110
+ effectActive = false ;
111
+ } ;
96
112
}
97
113
} , [ ref . current ] ) ;
98
114
You can’t perform that action at this time.
0 commit comments