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.
Utilização
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 componentAssinaturas
<T>(source: ReadonlySignal<T> | (() => T), fn: (next: T, previous: T | undefined) => void | (() => void), options?: { immediate?: boolean; }, name?: string): EventSubscriptionParâmetros de tipo
| Nome | Restrição | Predefinição |
|---|---|---|
T | — | — |
Parâmetros
| Nome | Tipo | Obrigatório | Descrição |
|---|---|---|---|
source | ReadonlySignal<T> | (() => T) | Sim | — |
fn | (next: T, previous: T | undefined) => void | (() => void) | Sim | — |
options | { immediate?: boolean;} | Não | — Predefinição: {} |
name | string | Não | — |
Devolve
Gerado a partir das declarações TypeScript públicas: assinaturas, props e predefinições vêm da fonte verificada, as descrições da sua JSDoc. Nenhuma predefinição é inventada.