Skip to content

Commit 5f92e4f

Browse files
committed
Update documentation
1 parent 6621027 commit 5f92e4f

File tree

2 files changed

+32
-27
lines changed

2 files changed

+32
-27
lines changed

README.md

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,25 @@ React Hooks are not currently supported in React Native. As soon as they are, s
2525

2626
### Auth
2727

28-
React Firebase Hooks provides a convenience listeners for Firebase Auth's current user. The hook wraps around the `firebase.auth().onAuthStateChange()` method to ensure that it is always up to date.
28+
React Firebase Hooks provides a convenience listener for Firebase Auth's auth state. The hook wraps around the `firebase.auth().onAuthStateChange()` method to ensure that it is always up to date.
2929

30-
#### `useCurrentUser()`
30+
#### `useAuthState(auth)`
31+
32+
Parameters:
33+
- `auth`: `firebase.auth.Auth`
3134

3235
Returns:
33-
`CurrentUser` containing:
36+
`AuthState` containing:
3437
- `initialising`: If the listener is still waiting for the user to be loaded
3538
- `user`: The `firebase.User`, or `null`, if no user is logged in
3639

3740
Example:
3841

3942
```js
40-
import { useCurrentUser } from 'react-firebase-hooks';
43+
import { useAuthState } from 'react-firebase-hooks/auth';
4144

4245
const CurrentUser = () => {
43-
const { initialising, user } = useCurrentUser();
46+
const { initialising, user } = useAuthState(firebase.auth());
4447
const login = () => {
4548
firebase.auth().signInWithEmailAndPassword('[email protected]', 'password');
4649
};
@@ -71,29 +74,29 @@ const CurrentUser = () => {
7174
### Cloud Firestore
7275

7376
React Firebase Hooks provides convenience listeners for Collections and Documents stored with
74-
Cloud Firestore. The hooks wrap around the `firebase.firestore().collection().onSnapshot()`
77+
Cloud Firestore. The hooks wrap around the `firebase.firestore.collection().onSnapshot()`
7578
and `firebase.firestore().doc().onSnapshot()` methods.
7679

7780
In addition to returning the snapshot value, the hooks provide an `error` and `loading` property
7881
to give a complete lifecycle for loading and listening to Cloud Firestore.
7982

80-
#### `useFirestoreCollection(pathOrQuery)`
83+
#### `useCollection(query)`
8184

8285
Parameters:
83-
- `pathOrQuery`: `string` | `firebase.firestore.Query`
86+
- `query`: `firebase.firestore.Query`
8487

8588
Returns:
86-
`FirestoreCollectionValue` containing
89+
`CollectionValue` containing
8790
- `error`: An optional `firebase.FirebaseError` returned by Firebase
8891
- `loading`: A `boolean` to indicate if the listener is still being loaded
8992
- `value`: A `firebase.firestore.QuerySnapshot`
9093

9194
Example:
9295
```js
93-
import { useFirestoreCollection } from 'react-firebase-hooks';
96+
import { useCollection } from 'react-firebase-hooks/firestore';
9497

9598
const FirestoreCollection = () => {
96-
const { error, loading, value } = useFirestoreCollection('hooks');
99+
const { error, loading, value } = useCollection(firebase.firestore().collection('hooks'));
97100
return (
98101
<div>
99102
<p>
@@ -113,21 +116,23 @@ const FirestoreCollection = () => {
113116
}
114117
```
115118

116-
#### `useFirestoreDocument(pathOrRef)`
119+
#### `useDocument(docRef)`
117120

118121
Parameters:
119-
- `pathOrRef`: `string` | `firebase.firestore.DocumentReference`
122+
- `docRef`: `firebase.firestore.DocumentReference`
120123

121124
Returns:
122-
`FirestoreDocumentValue` containing
125+
`DocumentValue` containing
123126
- `error`: An optional `firebase.FirebaseError` returned by Firebase
124127
- `loading`: A `boolean` to indicate if the listener is still being loaded
125128
- `value`: A `firebase.firestore.DocumentSnapshot`
126129

127130
Example:
128131
```js
132+
import { useDocument } from 'react-firebase-hooks/firestore';
133+
129134
const FirestoreDocument = () => {
130-
const { error, loading, value } = useFirestoreDocument('hooks/nBShXiRGFAhuiPfBaGpt');
135+
const { error, loading, value } = useDocument(firebase.firestore().doc('hooks/nBShXiRGFAhuiPfBaGpt'));
131136
return (
132137
<div>
133138
<p>
@@ -153,23 +158,23 @@ Firebase Realtime Database. The hooks wrap around the `firebase.database().ref(
153158
In addition to returning the list or value, the hooks provide an `error` and `loading` property
154159
to give a complete lifecycle for loading and listening to the Realtime Database.
155160

156-
#### `useDatabaseList(pathOrRef)`
161+
#### `useList(ref)`
157162

158163
Parameters:
159-
- `pathOrRef`: `string` | `firebase.database.Reference`
164+
- `ref`: `firebase.database.Reference`
160165

161166
Returns:
162-
`DatabaseList` containing
167+
`ListValue` containing
163168
- `error`: An optional error object returned by Firebase
164-
- `list`: A list of `firebase.database.DataSnapshot`
165169
- `loading`: A `boolean` to indicate if the listener is still being loaded
170+
- `value`: A list of `firebase.database.DataSnapshot`
166171

167172
Example:
168173
```js
169-
import { useDatabaseList } from 'react-firebase-hooks';
174+
import { useList } from 'react-firebase-hooks/database';
170175

171176
const DatabaseList = () => {
172-
const { error, list, loading } = useDatabaseList('list');
177+
const { error, list, loading } = useList(firebase.database().ref('list'));
173178

174179
return (
175180
<div>
@@ -190,23 +195,23 @@ const DatabaseList = () => {
190195
};
191196
```
192197

193-
#### `useDatabaseValue(pathOrRef)`
198+
#### `useObject(ref)`
194199

195200
Parameters:
196-
- `pathOrRef`: `string` | `firebase.database.Reference`
201+
- `ref`: `firebase.database.Reference`
197202

198203
Returns:
199-
`DatabaseValue` containing
204+
`ObjectValue` containing
200205
- `error`: An optional error object returned by Firebase
201206
- `loading`: A `boolean` to indicate if the listener is still being loaded
202207
- `value`: A `firebase.database.DataSnapshot`
203208

204209
Example:
205210
```js
206-
import { useDatabaseValue } from 'react-firebase-hooks';
211+
import { useObject } from 'react-firebase-hooks/database';
207212

208213
const DatabaseValue = () => {
209-
const { error, loading, value } = useDatabaseValue('value');
214+
const { error, loading, value } = useObject(firebase.database().ref('value'));
210215

211216
return (
212217
<div>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-firebase-hooks",
3-
"version": "0.3.0-alpha.11",
3+
"version": "0.3.0-alpha.14",
44
"description": "React Hooks for Firebase",
55
"author": "CS Frequency Limited (https://csfrequency.com)",
66
"license": "Apache-2.0",

0 commit comments

Comments
 (0)