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.
Verwendung
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 componentSignaturen
<T>(source: ReadonlySignal<T> | (() => T), fn: (next: T, previous: T | undefined) => void | (() => void), options?: { immediate?: boolean; }, name?: string): EventSubscriptionTypparameter
| Name | Einschränkung | Standard |
|---|---|---|
T | — | — |
Parameter
| Name | Typ | Erforderlich | Beschreibung |
|---|---|---|---|
source | ReadonlySignal<T> | (() => T) | Ja | — |
fn | (next: T, previous: T | undefined) => void | (() => void) | Ja | — |
options | { immediate?: boolean;} | Nein | — Standard: {} |
name | string | Nein | — |
Rückgabe
Generiert aus den öffentlichen TypeScript-Deklarationen: Signaturen, Props und Standardwerte stammen aus der geprüften Quelle, Beschreibungen aus deren JSDoc. Kein Standardwert ist erfunden.