@@ -25,22 +25,25 @@ React Hooks are not currently supported in React Native. As soon as they are, s
25
25
26
26
### Auth
27
27
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.
29
29
30
- #### ` useCurrentUser() `
30
+ #### ` useAuthState(auth) `
31
+
32
+ Parameters:
33
+ - ` auth ` : ` firebase.auth.Auth `
31
34
32
35
Returns:
33
- ` CurrentUser ` containing:
36
+ ` AuthState ` containing:
34
37
- ` initialising ` : If the listener is still waiting for the user to be loaded
35
38
- ` user ` : The ` firebase.User ` , or ` null ` , if no user is logged in
36
39
37
40
Example:
38
41
39
42
``` js
40
- import { useCurrentUser } from ' react-firebase-hooks' ;
43
+ import { useAuthState } from ' react-firebase-hooks/auth ' ;
41
44
42
45
const CurrentUser = () => {
43
- const { initialising , user } = useCurrentUser ( );
46
+ const { initialising , user } = useAuthState ( firebase . auth () );
44
47
const login = () => {
45
48
firebase .
auth ().
signInWithEmailAndPassword (
' [email protected] ' ,
' password' );
46
49
};
@@ -71,29 +74,29 @@ const CurrentUser = () => {
71
74
### Cloud Firestore
72
75
73
76
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() `
75
78
and ` firebase.firestore().doc().onSnapshot() ` methods.
76
79
77
80
In addition to returning the snapshot value, the hooks provide an ` error ` and ` loading ` property
78
81
to give a complete lifecycle for loading and listening to Cloud Firestore.
79
82
80
- #### ` useFirestoreCollection(pathOrQuery )`
83
+ #### ` useCollection(query )`
81
84
82
85
Parameters:
83
- - ` pathOrQuery ` : ` string ` | ` firebase.firestore.Query `
86
+ - ` query ` : ` firebase.firestore.Query `
84
87
85
88
Returns:
86
- ` FirestoreCollectionValue ` containing
89
+ ` CollectionValue ` containing
87
90
- ` error ` : An optional ` firebase.FirebaseError ` returned by Firebase
88
91
- ` loading ` : A ` boolean ` to indicate if the listener is still being loaded
89
92
- ` value ` : A ` firebase.firestore.QuerySnapshot `
90
93
91
94
Example:
92
95
``` js
93
- import { useFirestoreCollection } from ' react-firebase-hooks' ;
96
+ import { useCollection } from ' react-firebase-hooks/firestore ' ;
94
97
95
98
const FirestoreCollection = () => {
96
- const { error , loading , value } = useFirestoreCollection ( ' hooks' );
99
+ const { error , loading , value } = useCollection ( firebase . firestore (). collection ( ' hooks' ) );
97
100
return (
98
101
< div>
99
102
< p>
@@ -113,21 +116,23 @@ const FirestoreCollection = () => {
113
116
}
114
117
```
115
118
116
- #### ` useFirestoreDocument(pathOrRef )`
119
+ #### ` useDocument(docRef )`
117
120
118
121
Parameters:
119
- - ` pathOrRef ` : ` string ` | ` firebase.firestore.DocumentReference `
122
+ - ` docRef ` : ` firebase.firestore.DocumentReference `
120
123
121
124
Returns:
122
- ` FirestoreDocumentValue ` containing
125
+ ` DocumentValue ` containing
123
126
- ` error ` : An optional ` firebase.FirebaseError ` returned by Firebase
124
127
- ` loading ` : A ` boolean ` to indicate if the listener is still being loaded
125
128
- ` value ` : A ` firebase.firestore.DocumentSnapshot `
126
129
127
130
Example:
128
131
``` js
132
+ import { useDocument } from ' react-firebase-hooks/firestore' ;
133
+
129
134
const FirestoreDocument = () => {
130
- const { error , loading , value } = useFirestoreDocument ( ' hooks/nBShXiRGFAhuiPfBaGpt' );
135
+ const { error , loading , value } = useDocument ( firebase . firestore (). doc ( ' hooks/nBShXiRGFAhuiPfBaGpt' ) );
131
136
return (
132
137
< div>
133
138
< p>
@@ -153,23 +158,23 @@ Firebase Realtime Database. The hooks wrap around the `firebase.database().ref(
153
158
In addition to returning the list or value, the hooks provide an ` error ` and ` loading ` property
154
159
to give a complete lifecycle for loading and listening to the Realtime Database.
155
160
156
- #### ` useDatabaseList(pathOrRef )`
161
+ #### ` useList(ref )`
157
162
158
163
Parameters:
159
- - ` pathOrRef ` : ` string ` | ` firebase.database.Reference `
164
+ - ` ref ` : ` firebase.database.Reference `
160
165
161
166
Returns:
162
- ` DatabaseList ` containing
167
+ ` ListValue ` containing
163
168
- ` error ` : An optional error object returned by Firebase
164
- - ` list ` : A list of ` firebase.database.DataSnapshot `
165
169
- ` loading ` : A ` boolean ` to indicate if the listener is still being loaded
170
+ - ` value ` : A list of ` firebase.database.DataSnapshot `
166
171
167
172
Example:
168
173
``` js
169
- import { useDatabaseList } from ' react-firebase-hooks' ;
174
+ import { useList } from ' react-firebase-hooks/database ' ;
170
175
171
176
const DatabaseList = () => {
172
- const { error , list , loading } = useDatabaseList ( ' list' );
177
+ const { error , list , loading } = useList ( firebase . database (). ref ( ' list' ) );
173
178
174
179
return (
175
180
< div>
@@ -190,23 +195,23 @@ const DatabaseList = () => {
190
195
};
191
196
```
192
197
193
- #### ` useDatabaseValue(pathOrRef )`
198
+ #### ` useObject(ref )`
194
199
195
200
Parameters:
196
- - ` pathOrRef ` : ` string ` | ` firebase.database.Reference `
201
+ - ` ref ` : ` firebase.database.Reference `
197
202
198
203
Returns:
199
- ` DatabaseValue ` containing
204
+ ` ObjectValue ` containing
200
205
- ` error ` : An optional error object returned by Firebase
201
206
- ` loading ` : A ` boolean ` to indicate if the listener is still being loaded
202
207
- ` value ` : A ` firebase.database.DataSnapshot `
203
208
204
209
Example:
205
210
``` js
206
- import { useDatabaseValue } from ' react-firebase-hooks' ;
211
+ import { useObject } from ' react-firebase-hooks/database ' ;
207
212
208
213
const DatabaseValue = () => {
209
- const { error , loading , value } = useDatabaseValue ( ' value' );
214
+ const { error , loading , value } = useObject ( firebase . database (). ref ( ' value' ) );
210
215
211
216
return (
212
217
< div>
0 commit comments