Files
stack/packages/mosaic/framework/skills/vueuse-functions/references/useRTDB.md
T
fargo 1a822493ba format: apply repo prettier (3.8.1) to the folded skills tree
963 markdown files reformatted with the repository's pinned prettier so
pnpm format:check covers the folded tree like every other repo file.

The formatter's embedded-language pass also normalized code fences
(TS semicolons, closed HTML tags in examples, lowercased CSS hex colors,
one renumbered list that skipped an index). Alphanumeric token deltas vs
the fold commit were audited file-by-file; all are formatter-equivalent
markup normalizations plus the four sanitized skills.
2026-08-19 14:37:17 -05:00

1.5 KiB

category
category
@Firebase

useRTDB

Reactive Firebase Realtime Database binding. Making it straightforward to always keep your local data in sync with remotes databases.

Usage

import { useRTDB } from '@vueuse/firebase/useRTDB';
import { initializeApp } from 'firebase/app';
import { getDatabase } from 'firebase/database';

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

// @filename: store.ts
// ---cut---
// store.ts
import { createGlobalState } from '@vueuse/core';
import { useRTDB } from '@vueuse/firebase/useRTDB';

export const useTodos = createGlobalState(() => useRTDB(db.ref('todos')));
<!-- app.vue -->
<script setup lang="ts">
// @include: store
// ---cut---
import { useTodos } from './store';

const todos = useTodos();
</script>

Type Declarations

export interface UseRTDBOptions {
  errorHandler?: (err: Error) => void;
  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, T | undefined>;