watch-once
Watch sources like Vue's watch, delivering exactly one change and then stopping.
| Package | @vizejs/composable/watch-once |
| Own the source | vize lib pull composable:watch-once |
| Runtime exports | watchOnce |
| Gzip budget | 256 B |
Minimal setup
Use a Vue 3.5+ project with Vue SFC compilation configured (see Vite+ integration).
vp install @vizejs/composable
Import the entry directly. Call lifecycle-bound utilities inside <script setup> so cleanup follows the component scope; consult the runtime contract for this entry's SSR and hydration behavior.
import { watchOnce } from "@vizejs/composable/watch-once";
Runtime contract
| Utility | Category | Stability | SSR | Hydration | Cleanup | Targets | Host globals | Uses |
|---|---|---|---|---|---|---|---|---|
watchOnce |
reactivity | experimental | safe | not-applicable | caller, reactive-scope | web, server, worker, native, desktop, terminal | — | — |
API
watchOnce
Watch sources like Vue's watch, delivering exactly one change and then stopping. A thin, typed shorthand for watch(source, callback, { once: true }): with immediate: true the single call is the immediate one. The returned handle can stop the watcher before it fires. Safe during server rendering and bound to the owning reactive scope.
function watchOnce< const Sources extends WatchSources, Immediate extends Readonly<boolean> = false, >( source: Sources, callback: WatchHelperCallback<Sources, Immediate>, options?: WatchOnceOptions<Immediate>, ): WatchHandle
watchOnce(user, (loaded) => track("first-user", loaded.id));
watchOnce
function watchOnce( source: WatchSources, callback: WatchCallback<unknown, unknown>, options: WatchOnceOptions<boolean> = {}, ): WatchHandle