Function: effect()
ts
function effect(fn: EffectFn, options?: EffectOptions): DisposeFn;Defined in: @preact/signals-core:
Create an effect to run arbitrary code in response to signal changes.
An effect tracks which signals are accessed within the given callback function fn, and re-runs the callback when those signals change.
The callback may return a cleanup function. The cleanup function gets run once, either when the callback is next called or when the effect gets disposed, whichever happens first.
Parameters
| Parameter | Type | Description |
|---|---|---|
fn | EffectFn | The effect callback. |
options? | EffectOptions | - |
Returns
DisposeFn
A function for disposing the effect.