You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**This documentation is for v3 of React Firebase Hooks which involved a number of breaking changes, including adding support for Firebase v8.0.0 - more details [here](https://github.com/CSFrequency/react-firebase-hooks/releases/tag/v3.0.0). For v2 documentation, see [here](https://github.com/CSFrequency/react-firebase-hooks/tree/v2.2.0).**
10
+
This documentation is for v4 of React Firebase Hooks which involved a number of breaking changes, including adding support for Firebase v9 - more details [here](https://github.com/CSFrequency/react-firebase-hooks/releases/tag/v4.0.0).
11
+
- For v3 documentation (Firebase v8), see [here](https://github.com/CSFrequency/react-firebase-hooks/tree/v3.0.0).
12
+
- For v2 documentation, see [here](https://github.com/CSFrequency/react-firebase-hooks/tree/v2.2.0).
9
13
10
14
## Installation
11
15
12
-
React Firebase Hooks v3 requires **React 16.8.0 or later** and **Firebase v8.0.0 or later**.
16
+
React Firebase Hooks v4 requires **React 16.8.0 or later** and **Firebase v9.0.0 or later**.
13
17
14
18
> Official support for Hooks was added to React Native in v0.59.0. React Firebase Hooks works with both the Firebase JS SDK and React Native Firebase, although some of the typings may be incorrect.
15
19
@@ -29,6 +33,10 @@ There has been a **lot** of hype around React Hooks, but this hype merely reflec
29
33
30
34
This library explores how React Hooks can work to make integration with Firebase even more straightforward than it already is. It takes inspiration for naming from RxFire and is based on an internal library that we had been using in a number of apps prior to the release of React Hooks. The implementation with hooks is 10x simpler than our previous implementation.
31
35
36
+
## Upgrading from v3 to v4
37
+
38
+
To upgrade your project from v3 to v4 check out the [Release Notes](https://github.com/CSFrequency/react-firebase-hooks/releases/tag/v4.0.0) which have full details of everything that needs to be changed.
39
+
32
40
## Upgrading from v2 to v3
33
41
34
42
To upgrade your project from v2 to v3 check out the [Release Notes](https://github.com/CSFrequency/react-firebase-hooks/releases/tag/v3.0.1) which have full details of everything that needs to be changed.
Copy file name to clipboardExpand all lines: auth/README.md
+18-15Lines changed: 18 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# React Firebase Hooks - Auth
2
2
3
-
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.
3
+
React Firebase Hooks provides a convenience listener for Firebase Auth's auth state. The hook wraps around the `auth.onAuthStateChange(auth.getAuth(firebaseApp))` method to ensure that it is always up to date.
4
4
5
5
All hooks can be imported from `react-firebase-hooks/auth`, e.g.
6
6
@@ -24,30 +24,33 @@ Retrieve and monitor the authentication state from Firebase.
24
24
25
25
The `useAuthState` hook takes the following parameters:
26
26
27
-
-`auth`: `firebase.auth.Auth` instance for the app you would like to monitor
27
+
-`auth`: `auth.Auth` instance for the app you would like to monitor
28
28
29
29
Returns:
30
30
31
-
-`user`: The `firebase.User` if logged in, or `undefined` if not
31
+
-`user`: The `auth.User` if logged in, or `undefined` if not
32
32
-`loading`: A `boolean` to indicate whether the the authentication state is still being loaded
33
-
-`error`: Any `firebase.auth.Error` returned by Firebase when trying to load the user, or `undefined` if there is no error
33
+
-`error`: Any `AuthError` returned by Firebase when trying to load the user, or `undefined` if there is no error
34
34
35
35
#### If you are registering or signing in the user for the first time consider using [useCreateUserWithEmailAndPassword](#usecreateuserwithemailandpassword), [useSignInWithEmailAndPassword](#usesigninwithemailandpassword)
Login a user with email and password. Wraps the underlying `firebase.auth().signInWithEmailAndPassword` method and provides additional `loading` and `error` information.
171
+
Login a user with email and password. Wraps the underlying `auth.signInWithEmailAndPassword` method and provides additional `loading` and `error` information.
169
172
170
173
The `useSignInWithEmailAndPassword` hook takes the following parameters:
171
174
172
-
-`auth`: `firebase.auth.Auth` instance for the app you would like to monitor
175
+
-`auth`: `Auth` instance for the app you would like to monitor
173
176
174
177
Returns:
175
178
176
179
-`signInWithEmailAndPassword(email: string, password: string)`: a function you can call to start the login
177
-
-`user`: The `firebase.User` if the user was logged in or `undefined` if not
180
+
-`user`: The `auth.User` if the user was logged in or `undefined` if not
178
181
-`loading`: A `boolean` to indicate whether the the user login is processing
179
-
-`error`: Any `firebase.auth.Error` returned by Firebase when trying to login the user, or `undefined` if there is no error
182
+
-`error`: Any `Error` returned by Firebase when trying to login the user, or `undefined` if there is no error
As `useList`, but this hooks extracts the `firebase.database.DataSnapshot.key` values, rather than the the `firebase.database.DataSnapshot`s themselves.
88
+
As `useList`, but this hooks extracts the `database.DataSnapshot.key` values, rather than the the `database.DataSnapshot`s themselves.
81
89
82
90
The `useListKeys` hook takes the following parameters:
83
91
84
-
-`reference`: (optional) `firebase.database.Reference` for the data you would like to load
92
+
-`reference`: (optional) `database.Reference` for the data you would like to load
85
93
86
94
Returns:
87
95
88
96
-`keys`: an array of `string`, or `undefined` if no reference is supplied
89
97
-`loading`: a `boolean` to indicate if the data is still being loaded
90
-
-`error`: Any `firebase.FirebaseError` returned by Firebase when trying to load the data, or `undefined` if there is no error
98
+
-`error`: Any `Error` returned by Firebase when trying to load the data, or `undefined` if there is no error
As `useList`, but this hook extracts a typed list of the `firebase.database.DataSnapshot.val()` values, rather than the the
99
-
`firebase.database.DataSnapshot`s themselves.
106
+
As `useList`, but this hook extracts a typed list of the `database.DataSnapshot.val()` values, rather than the the
107
+
`database.DataSnapshot`s themselves.
100
108
101
109
The `useListVals` hook takes the following parameters:
102
110
103
-
-`reference`: (optional) `firebase.database.Reference` for the data you would like to load
111
+
-`reference`: (optional) `database.Reference` for the data you would like to load
104
112
-`options`: (optional) `Object` with the following parameters:
105
-
-`keyField`: (optional) `string` field name that should be populated with the `firebase.database.DataSnapshot.id` property in the returned values.
106
-
-`refField`: (optional) `string` field name that should be populated with the `firebase.database.DataSnapshot.ref` property.
107
-
-`transform`: (optional) a function that receives the raw `firebase.database.DataSnapshot.val()` for each item in the list to allow manual transformation of the data where required by the application. See [`Transforming data`](#transforming-data) below.
113
+
-`keyField`: (optional) `string` field name that should be populated with the `database.DataSnapshot.id` property in the returned values.
114
+
-`refField`: (optional) `string` field name that should be populated with the `database.DataSnapshot.ref` property.
115
+
-`transform`: (optional) a function that receives the raw `database.DataSnapshot.val()` for each item in the list to allow manual transformation of the data where required by the application. See [`Transforming data`](#transforming-data) below.
108
116
109
117
Returns:
110
118
111
119
-`values`: an array of `T`, or `undefined` if no reference is supplied
112
120
-`loading`: a `boolean` to indicate if the data is still being loaded
113
-
-`error`: Any `firebase.FirebaseError` returned by Firebase when trying to load the data, or `undefined` if there is no error
121
+
-`error`: Any `Error` returned by Firebase when trying to load the data, or `undefined` if there is no error
114
122
115
123
### useObject
116
124
@@ -122,21 +130,24 @@ Retrieve and monitor an object or primitive value in the Firebase Realtime Datab
122
130
123
131
The `useObject` hook takes the following parameters:
124
132
125
-
-`reference`: (optional) `firebase.database.Reference` for the data you would like to load
133
+
-`reference`: (optional) `database.Reference` for the data you would like to load
126
134
127
135
Returns:
128
136
129
-
-`snapshot`: a `firebase.database.DataSnapshot`, or `undefined` if no reference is supplied
137
+
-`snapshot`: a `database.DataSnapshot`, or `undefined` if no reference is supplied
130
138
-`loading`: a `boolean` to indicate if the data is still being loaded
131
-
-`error`: Any `firebase.FirebaseError` returned by Firebase when trying to load the data, or `undefined` if there is no error
139
+
-`error`: Any `Error` returned by Firebase when trying to load the data, or `undefined` if there is no error
As `useObject`, but this hook returns the typed contents of `firebase.database.DataSnapshot.val()`, rather than the the
160
-
`firebase.database.DataSnapshot` itself.
170
+
As `useObject`, but this hook returns the typed contents of `database.DataSnapshot.val()`, rather than the the
171
+
`database.DataSnapshot` itself.
161
172
162
173
The `useObjectVal` hook takes the following parameters:
163
174
164
-
-`reference`: (optional) `firebase.database.Reference` for the data you would like to load
175
+
-`reference`: (optional) `database.Reference` for the data you would like to load
165
176
-`options`: (optional) `Object` with the following parameters:
166
-
-`keyField`: (optional) `string` field name that should be populated with the `firebase.database.DataSnapshot.key` property in the returned value.
167
-
-`refField`: (optional) `string` field name that should be populated with the `firebase.database.DataSnapshot.ref` property.
168
-
-`transform`: (optional) a function that receives the raw `firebase.database.DataSnapshot.val()` to allow manual transformation of the data where required by the application. See [`Transforming data`](#transforming-data) below.
177
+
-`keyField`: (optional) `string` field name that should be populated with the `database.DataSnapshot.key` property in the returned value.
178
+
-`refField`: (optional) `string` field name that should be populated with the `database.DataSnapshot.ref` property.
179
+
-`transform`: (optional) a function that receives the raw `database.DataSnapshot.val()` to allow manual transformation of the data where required by the application. See [`Transforming data`](#transforming-data) below.
169
180
170
181
Returns:
171
182
172
183
-`value`: a `T`, or `undefined` if no reference is supplied
173
184
-`loading`: a `boolean` to indicate if the data is still being loaded
174
-
-`error`: Any `firebase.FirebaseError` returned by Firebase when trying to load the data, or `undefined` if there is no error
185
+
-`error`: Any `FirebaseError` returned by Firebase when trying to load the data, or `undefined` if there is no error
0 commit comments