ref-auto-reset
Writable ref that falls back to a default value afterMs milliseconds after each write.
| Package | @vizejs/composable/ref-auto-reset |
| Own the source | vize lib pull composable:ref-auto-reset |
| Runtime exports | refAutoReset |
| Gzip budget | 1792 B |
Usage
import { refAutoReset } from "@vizejs/composable/ref-auto-reset";
Runtime contract
| Utility | Category | Stability | SSR | Hydration | Cleanup | Targets | Host globals | Uses |
|---|---|---|---|---|---|---|---|---|
refAutoReset |
reactivity | experimental | deterministic-fallback | stable | reactive-scope | web, server, worker, native, desktop, terminal | globalThis, window |
tryOnScopeDispose |
API
refAutoReset
Writable ref that falls back to a default value afterMs milliseconds after each write. Typical for transient UI state such as "Copied!" labels. Every write restarts the timer; the default (itself possibly reactive) is read when the reset happens, and the ref reads the current default until the first write. The pending reset is cancelled when the owning reactive scope stops. Without a browser window (and without runOnServer) no timer starts.
function refAutoReset<Value>( defaultValue: MaybeRefOrGetter<Value>, afterMs: MaybeRefOrGetter<number>, options: RefAutoResetOptions = {}, ): Ref<Value>
const message = refAutoReset("", 2_000);
message.value = "Copied!"; // back to "" after two seconds
Types
RefAutoResetOptions
Options for refAutoReset.
| Member | Type | Description |
|---|---|---|
runOnServer? |
boolean |
Applies the reset timer when no browser window is available. When disabled, written values persist on the server (a render is a snapshot). |
scheduler? |
TimeoutScheduler |
Owns the reset timer. |