📄 useRTDB¶
📊 Analysis Summary¶
| Metric | Count |
|---|---|
| 🔧 Functions | 2 |
| 📦 Imports | 6 |
| 📐 Interfaces | 1 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/firebase/useRTDB/index.ts
📦 Imports¶
| Name | Source |
|---|---|
DatabaseReference |
firebase/database |
DataSnapshot |
firebase/database |
Ref |
vue |
tryOnScopeDispose |
@vueuse/shared |
onValue |
firebase/database |
deepRef |
vue |
Functions¶
useRTDB(docRef: DatabaseReference, options: UseRTDBOptions): Ref<T>¶
Reactive Firebase Realtime Database binding.
See: https://vueuse.org/useRTDB
Calls:
console.errordeepRef (from vue)snapshot.valonValue (from firebase/database)tryOnScopeDispose (from @vueuse/shared)off
Code
export function useRTDB<T = any>(
docRef: DatabaseReference,
options: UseRTDBOptions = {},
) {
const {
errorHandler = (err: Error) => console.error(err),
autoDispose = true,
} = options
const data = deepRef(undefined) as Ref<T | undefined>
function update(snapshot: DataSnapshot) {
data.value = snapshot.val()
}
const off = onValue(docRef, update, errorHandler)
if (autoDispose)
tryOnScopeDispose(() => off())
return data
}
Internal helpers¶
Declared inside another function in this file.
update(snapshot: DataSnapshot): void¶
Parameters:
snapshotDataSnapshot
Returns: void
Calls:
snapshot.val
Interfaces¶
UseRTDBOptions¶
Interface Code
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
errorHandler |
(err: Error) => void |
✓ | not shown |
autoDispose |
boolean |
✓ | not shown |
Generated by Syntax Scribe