@@ -90,11 +90,17 @@ and `firebase.firestore().doc().onSnapshot()` methods.
90
90
In addition to returning the snapshot value, the hooks provide an ` error ` and ` loading ` property
91
91
to give a complete lifecycle for loading and listening to Cloud Firestore.
92
92
93
- #### ` useCollection(query) `
93
+ There are 2 variants of each hook:
94
+
95
+ - ` useX ` which subscribes to the underlying Collection or Document and listens for changes
96
+ - ` useXOnce ` which reads the current value of the Collection or Document
97
+
98
+ #### ` useCollection(query, options) `
94
99
95
100
Parameters:
96
101
97
102
- ` query ` : ` firebase.firestore.Query `
103
+ - ` options ` : ` firebase.firestore.SnapshotListenOptions `
98
104
99
105
Returns:
100
106
` CollectionHook ` containing
@@ -133,11 +139,56 @@ const FirestoreCollection = () => {
133
139
};
134
140
```
135
141
142
+ #### ` useCollectionOnce(query, options) `
143
+
144
+ Parameters:
145
+
146
+ - ` query ` : ` firebase.firestore.Query `
147
+ - ` options ` : ` firebase.firestore.GetOptions `
148
+
149
+ Returns:
150
+ ` CollectionHook ` containing
151
+
152
+ - ` error ` : An optional ` firebase.FirebaseError ` returned by Firebase
153
+ - ` loading ` : A ` boolean ` to indicate if the listener is still being loaded
154
+ - ` value ` : A ` firebase.firestore.QuerySnapshot `
155
+
156
+ Import:
157
+
158
+ ``` js
159
+ import { useCollectionOnce } from ' react-firebase-hooks/firestore' ;
160
+ ```
161
+
162
+ #### ` useCollectionData<T>(ref, idField) `
163
+
164
+ As ` useCollection ` , but this hook returns a typed list of the
165
+ ` QuerySnapshot.docs ` values, rather than the the ` QuerySnapshot ` itself.
166
+
167
+ Parameters:
168
+
169
+ - ` query ` : ` firebase.firestore.Query `
170
+ - ` options ` : (Optional) ` firebase.firestore.GetOptions `
171
+ - ` idField ` : (Optional) Name of field that should be populated with the ` QuerySnapshot.id ` property
172
+
173
+ Returns:
174
+ ` CollectionDataHook ` containing
175
+
176
+ - ` error ` : An optional error object returned by Firebase
177
+ - ` loading ` : A ` boolean ` to indicate if the listener is still being loaded
178
+ - ` value ` : A list of ` firebase.firestore.DocumentSnapshot.data() ` values, combined with the optional id field
179
+
180
+ Import:
181
+
182
+ ``` js
183
+ import { useCollectionData } from ' react-firebase-hooks/firestore' ;
184
+ ```
185
+
136
186
#### ` useDocument(docRef) `
137
187
138
188
Parameters:
139
189
140
190
- ` docRef ` : ` firebase.firestore.DocumentReference `
191
+ - ` options ` : (Optional) ` firebase.firestore.SnapshotListenOptions `
141
192
142
193
Returns:
143
194
` DocumentHook ` containing
@@ -167,6 +218,71 @@ const FirestoreDocument = () => {
167
218
};
168
219
```
169
220
221
+ #### ` useDocumentOnce(docRef) `
222
+
223
+ Parameters:
224
+
225
+ - ` docRef ` : ` firebase.firestore.DocumentReference `
226
+ - ` options ` : (Optional) ` firebase.firestore.GetOptions `
227
+
228
+ Returns:
229
+ ` DocumentHook ` containing
230
+
231
+ - ` error ` : An optional ` firebase.FirebaseError ` returned by Firebase
232
+ - ` loading ` : A ` boolean ` to indicate if the listener is still being loaded
233
+ - ` value ` : A ` firebase.firestore.DocumentSnapshot `
234
+
235
+ Import:
236
+
237
+ ``` js
238
+ import { useDocumentOnce } from ' react-firebase-hooks/firestore' ;
239
+ ```
240
+
241
+ #### ` useDocumentData<T>(ref) `
242
+
243
+ As ` useDocument ` , but this hook returns the typed contents of
244
+ ` DocumentSnapshot.val() ` rather than the ` DocumentSnapshot ` itself.
245
+
246
+ Parameters:
247
+
248
+ - ` docRef ` : ` firebase.firestore.DocumentReference `
249
+ - ` options ` : (Optional) ` firebase.firestore.SnapshotListenOptions `
250
+ - ` idField ` : (Optional) Name of field that should be populated with the ` DocumentSnapshot.id ` property
251
+
252
+ Returns:
253
+ ` DocumentDataHook ` containing
254
+
255
+ - ` error ` : An optional error object returned by Firebase
256
+ - ` loading ` : A ` boolean ` to indicate if the listener is still being loaded
257
+ - ` value ` : The contents of ` firebase.firestore.DocumentSnapshot.data() ` , combined with the optional id field
258
+
259
+ Import:
260
+
261
+ ``` js
262
+ import { useDocumentData } from ' react-firebase-hooks/firestore' ;
263
+ ```
264
+
265
+ #### ` useDocumentDataOnce<T>(ref) `
266
+
267
+ Parameters:
268
+
269
+ - ` docRef ` : ` firebase.firestore.DocumentReference `
270
+ - ` options ` : (Optional) ` firebase.firestore.GetOptions `
271
+ - ` idField ` : (Optional) Name of field that should be populated with the ` DocumentSnapshot.id ` property
272
+
273
+ Returns:
274
+ ` DocumentDataHook ` containing
275
+
276
+ - ` error ` : An optional error object returned by Firebase
277
+ - ` loading ` : A ` boolean ` to indicate if the listener is still being loaded
278
+ - ` value ` : The contents of ` firebase.firestore.DocumentSnapshot.data() ` , combined with the optional id field
279
+
280
+ Import:
281
+
282
+ ``` js
283
+ import { useDocumentDataOnce } from ' react-firebase-hooks/firestore' ;
284
+ ```
285
+
170
286
### Cloud Storage
171
287
172
288
React Firebase Hooks provides convenience listeners for files stored within
@@ -338,13 +454,14 @@ As above, but this hook returns the typed contents of `DataSnapshot.val()` rathe
338
454
Parameters:
339
455
340
456
- ` ref ` : ` firebase.database.Reference `
457
+ - ` keyField ` : (Optional) Name of field that should be populated with the ` DataSnapshot.key ` property
341
458
342
459
Returns:
343
460
` ObjectValHook ` containing
344
461
345
462
- ` error ` : An optional error object returned by Firebase
346
463
- ` loading ` : A ` boolean ` to indicate if the listener is still being loaded
347
- - ` value ` : The contents of ` firebase.database.DataSnapshot.val() `
464
+ - ` value ` : The contents of ` firebase.database.DataSnapshot.val() ` , combined with the optional key field
348
465
349
466
## License
350
467
0 commit comments