Skip to content

Function: onReActiveDatabaseReady()

ts
function onReActiveDatabaseReady(callback: () => void | Promise<void>): void;

Registers a callback to be invoked after the Vue ReActiveRecord database is ready in the current Vue component lifecycle.

This hook is SSR-safe: in SSR, the callback is invoked immediately after mounting; in the browser, it waits for the real database to be fully initialized (hydration-safe).

Use this to run logic that depends on the database being ready, such as queries, mutations, or subscriptions, without risking hydration mismatches or race conditions.

Parameters

ParameterTypeDescription
callback() => void | Promise<void>A function to run after the database is ready. Can be async. If the database is already ready, the callback runs immediately after mount.

Returns

void

Example

typescript
import {
  onReActiveDatabaseReady,
  useReActiveModel,
} from "@nhtio/vue-re-active-record";

onReActiveDatabaseReady(async () => {
  const User = useReActiveModel("user");
  const users = await User.all();
  // ...
});

Remarks

  • Always use this or awaitPluginInit before running queries in onMounted for hydration safety.
  • The callback is awaited if it returns a Promise.
  • This is a composable and should be called inside the setup() function of a Vue component.