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.
Utilisation
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): EventSubscriptionParamètres de type
| Nom | Contrainte | Par défaut |
|---|---|---|
T | — | — |
Paramètres
| Nom | Type | Requis | Description |
|---|---|---|---|
source | ReadonlySignal<T> | (() => T) | Oui | — |
fn | (next: T, previous: T | undefined) => void | (() => void) | Oui | — |
options | { immediate?: boolean;} | Non | — Par défaut: {} |
name | string | Non | — |
Retourne
Généré depuis les déclarations TypeScript publiques : signatures, props et valeurs par défaut viennent de la source vérifiée, les descriptions de sa JSDoc. Aucune valeur par défaut n'est inventée.