Skip to content

Commit d1db136

Browse files
committed
[database] Add flow types and docs for useObjectVal
1 parent 777db1f commit d1db136

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,22 @@ const DatabaseValue = () => {
230230

231231
```
232232

233+
#### `useObjectVal<T>(ref)`
234+
235+
As above, but this hook returns the typed contents of `DataSnapshot.val()` rather than the
236+
`DataSnapshot` itself.
237+
238+
Parameters:
239+
- `ref`: `firebase.database.Reference`
240+
241+
Returns:
242+
`ObjectValue` containing
243+
- `error`: An optional error object returned by Firebase
244+
- `loading`: A `boolean` to indicate if the listener is still being loaded
245+
- `value`: A `firebase.database.DataSnapshot`
246+
247+
```
248+
233249
## License
234250
235251
* See [LICENSE](/LICENSE)

database/index.js.flow

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ export type ObjectHook = {
1111
loading: boolean;
1212
value?: DataSnapshot;
1313
};
14+
export type ObjectValHook<T> = {
15+
error?: Object;
16+
loading: boolean;
17+
value?: T;
18+
};
1419

1520
declare export function useList(query: Query): ListHook;
1621
declare export function useObject(query: Query): ObjectHook;
22+
declare export function useObjectVal<T>(query: Query): ObjectValHook<T>;

0 commit comments

Comments
 (0)