Skip to content

Commit d7c57b1

Browse files
authored
docs(database): mention restrictions (#268)
Edited the readme to incorporate the restrictions described in issue 267.
1 parent 30846d3 commit d7c57b1

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

packages/firebase-database/README.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,33 +153,40 @@ If you are listening to a node with many children, only listening to data you ca
153153
```ts
154154
import { firebase } from '@nativescript/firebase-core';
155155

156-
const onChildAdd = firebase()
156+
const ref = firebase()
157157
.database()
158-
.ref('/users')
158+
.ref('/users');
159+
160+
const onChildAdd = ref
159161
.on('child_added', (snapshot) => {
160162
console.log('A new node has been added', snapshot.val());
161163
});
162164

163165
// Stop listening for updates when no longer required
164-
firebase().database().ref('/users').off('child_added', onChildAdd);
166+
ref.off('child_added', onChildAdd);
165167
```
168+
169+
166170
### Remove a reference event listener
167171

168172
To unsubscribe from an event, call the `off` method on the reference passing it the event name and the function that the `on` method returned. This can be used within any useEffect hooks to automatically unsubscribe when the hook needs to unsubscribe itself.
169173

170174
```ts
171175
import { firebase } from '@nativescript/firebase-core';
172176

173-
const onValueChange = firebase()
177+
const ref = firebase()
174178
.database()
175-
.ref(`/users/${userId}`)
179+
.ref(`/users/${userId}`);
180+
181+
const onValueChange = ref
176182
.on('value', (snapshot) => {
177183
console.log('User data: ', snapshot.val());
178184
});
179185

180186
// Stop listening for updates when no longer required
181-
firebase().database().ref(`/users/${userId}`).off('value', onValueChange);
187+
ref.off('value', onValueChange);
182188
```
189+
> **Note:** The `off` method requires the same `ref` as specified on the corresponding `on` method. The event handler specified in the `on` method must be unique. If a common event handler is used for multiple events, an anonymous function can be used to invoke the common handler.
183190
184191
### Data querying
185192

0 commit comments

Comments
 (0)