Skip to content

Commit 27d6674

Browse files
chore(update-plugins): Mon Sep 2 08:06:48 UTC 2024
1 parent 7fe95c1 commit 27d6674

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

plugins/firebase-database.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,14 @@ If you are listening to a node with many children, only listening to data you ca
168168
```ts
169169
import { firebase } from '@nativescript/firebase-core'
170170

171-
const onChildAdd = firebase()
172-
.database()
173-
.ref('/users')
174-
.on('child_added', snapshot => {
175-
console.log('A new node has been added', snapshot.val())
176-
})
171+
const ref = firebase().database().ref('/users')
172+
173+
const onChildAdd = ref.on('child_added', snapshot => {
174+
console.log('A new node has been added', snapshot.val())
175+
})
177176

178177
// Stop listening for updates when no longer required
179-
firebase().database().ref('/users').off('child_added', onChildAdd)
178+
ref.off('child_added', onChildAdd)
180179
```
181180

182181
### Remove a reference event listener
@@ -186,17 +185,22 @@ To unsubscribe from an event, call the `off` method on the reference passing it
186185
```ts
187186
import { firebase } from '@nativescript/firebase-core'
188187

189-
const onValueChange = firebase()
190-
.database()
191-
.ref(`/users/${userId}`)
192-
.on('value', snapshot => {
193-
console.log('User data: ', snapshot.val())
194-
})
188+
const ref = firebase().database().ref(`/users/${userId}`)
189+
190+
const onValueChange = ref.on('value', snapshot => {
191+
console.log('User data: ', snapshot.val())
192+
})
195193

196194
// Stop listening for updates when no longer required
197-
firebase().database().ref(`/users/${userId}`).off('value', onValueChange)
195+
ref.off('value', onValueChange)
198196
```
199197

198+
:::tip Note
199+
200+
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.
201+
202+
:::
203+
200204
### Data querying
201205

202206
Realtime Database provides support for basic querying of your data. When a reference node contains children, you can both order & limit the returned results.

0 commit comments

Comments
 (0)