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
| Parameter | Type | Description |
|---|---|---|
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
awaitPluginInitbefore running queries inonMountedfor 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.