watch
Runs fn when a signal, or what source reads, changes; with immediate,
once at the start too. Called while a component sets up, it follows the
source until the component unmounts; anywhere else, from now on. Either way
remove() stops it sooner.
Usage
Read the current color scheme.
// Read the current color scheme.
import { appearance, watch } from 'kuito';
appearance.colorScheme.value; // 'light' | 'dark' | null
appearance.fontScale.value; // 1 by default
watch(appearance.fontScale, (scale) => console.log(scale)); // in a componentSignatures
<T>(source: ReadonlySignal<T> | (() => T), fn: (next: T, previous: T | undefined) => void | (() => void), options?: { immediate?: boolean; }, name?: string): EventSubscriptionType parameters
| Name | Constraint | Default |
|---|---|---|
T | — | — |
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
source | ReadonlySignal<T> | (() => T) | Yes | — |
fn | (next: T, previous: T | undefined) => void | (() => void) | Yes | — |
options | { immediate?: boolean;} | No | — Default: {} |
name | string | No | — |
Returns
Generated from the public TypeScript declarations: signatures, props and defaults come from the checked source, descriptions from its JSDoc. No defaults are invented.