effect
Auto-tracks signals read synchronously and retracks on subsequent updates.
Usage
React to changes and clean up work.
// React to changes and clean up work.
import { Text, effect, signal } from 'kuito';
const query = signal('');
const results = signal<string[]>([]);
effect(() => {
const term = query.value;
// Waits for typing to pause; the cleanup cancels the timer before the next run.
const timer = setTimeout(async () => {
const response = await fetch(`https://api.example.com/search?q=${encodeURIComponent(term)}`);
results.value = (await response.json()) as string[];
}, 300);
return () => clearTimeout(timer);
});
<Text>{results.value.length} results</Text>;Signatures
(fn: () => void | (() => void), name?: string): voidParameters
| Name | Type | Required | Description |
|---|---|---|---|
fn | () => void | (() => void) | Yes | — |
name | string | No | — |
Returns
void
Generated from the public TypeScript declarations: signatures, props and defaults come from the checked source, descriptions from its JSDoc. No defaults are invented.