Skip to content

Commit 5a2759f

Browse files
committed
Update README with new firestore hooks
1 parent a72b6f4 commit 5a2759f

File tree

1 file changed

+119
-2
lines changed

1 file changed

+119
-2
lines changed

README.md

Lines changed: 119 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,17 @@ and `firebase.firestore().doc().onSnapshot()` methods.
9090
In addition to returning the snapshot value, the hooks provide an `error` and `loading` property
9191
to give a complete lifecycle for loading and listening to Cloud Firestore.
9292

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)`
9499

95100
Parameters:
96101

97102
- `query`: `firebase.firestore.Query`
103+
- `options`: `firebase.firestore.SnapshotListenOptions`
98104

99105
Returns:
100106
`CollectionHook` containing
@@ -133,11 +139,56 @@ const FirestoreCollection = () => {
133139
};
134140
```
135141

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+
136186
#### `useDocument(docRef)`
137187

138188
Parameters:
139189

140190
- `docRef`: `firebase.firestore.DocumentReference`
191+
- `options`: (Optional) `firebase.firestore.SnapshotListenOptions`
141192

142193
Returns:
143194
`DocumentHook` containing
@@ -167,6 +218,71 @@ const FirestoreDocument = () => {
167218
};
168219
```
169220

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+
170286
### Cloud Storage
171287

172288
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
338454
Parameters:
339455

340456
- `ref`: `firebase.database.Reference`
457+
- `keyField`: (Optional) Name of field that should be populated with the `DataSnapshot.key` property
341458

342459
Returns:
343460
`ObjectValHook` containing
344461

345462
- `error`: An optional error object returned by Firebase
346463
- `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
348465

349466
## License
350467

0 commit comments

Comments
 (0)