TIP
available in add-on @vueuse/firebase
useRTDB
Reactive Firebase Realtime Database binding. Making it straightforward to always keep your local data in sync with remotes databases.
Usage
import firebase from 'firebase/app'
import 'firebase/database'
import { useRTDB } from '@vueuse/firebase'
const db = firebase
.initializeApp({ databaseURL: 'https://MY-DATABASE.firebaseio.com' })
.database()
// in setup()
const todos = useRTDB(db.ref('todos'))
Share across instances
You can reuse the firebase reference by using createGlobalState
from the core package
// store.js
import { createGlobalState } from '@vueuse/core'
import { useRTDB } from '@vueuse/firebase'
export const useTodos = createGlobalState(
() => useRTDB(db.ref('todos')),
)
// app.js
import { useTodos } from './store'
new Vue({
setup() {
const todos = useTodos()
return { todos }
},
})
Type Declarations
/**
* Reactive Firebase Realtime Database binding.
*
* @see {@link /useRTDB}
* @param docRef
*/
export declare function useRTDB<T = any>(
docRef: firebase.database.Reference
): Ref<T | undefined>