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 |
Usage
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