Category | @Firebase |
---|---|
Export Size | 210 B |
Package | @vueuse/firebase |
Last Changed | 9 months ago |
Reactive Firebase Realtime Database binding. Making it straightforward to always keep your local data in sync with remotes databases. Available in the @vueuse/firebase add-on.
import { initializeApp } from 'firebase/app' import { getDatabase } from 'firebase/database' import { useRTDB } from '@vueuse/firebase/useRTDB' const app = initializeApp({ /* config */ }) const db = getDatabase(app) // in setup() const todos = useRTDB(db.ref('todos'))
You can reuse the db reference by passing autoDispose: false
const todos = useRTDB(db.ref('todos'), { autoDispose: false })
or use createGlobalState
from the core package
// store.js import { createGlobalState } from '@vueuse/core' import { useRTDB } from '@vueuse/firebase/useRTDB' export const useTodos = createGlobalState( () => useRTDB(db.ref('todos')), )
// app.js import { useTodos } from './store' const todos = useTodos()
export interface UseRTDBOptions { autoDispose?: boolean } /** * Reactive Firebase Realtime Database binding. * * @see https://vueuse.org/useRTDB */ export declare function useRTDB<T = any>( docRef: DatabaseReference, options?: UseRTDBOptions ): Ref<T | undefined>
© 2019-present Anthony Fu
Licensed under the MIT License.
https://vueuse.org/firebase/useRTDB/