index.effect
effect(fn, name?): DisposeFn
Creates and runs a reactive side-effect function immediately, re-running it whenever its dependencies mutate.
| Name | Type | Description |
|---|---|---|
fn |
EffectFn |
The reactive effect function to execute and re-run upon dependency change. |
name? |
string |
Optional diagnostic name for debugging, telemetry, and observability tracking. |
A DisposeFn that unbinds all reactive subscriptions and cleans up resources.
Remarks
When effect is invoked, the supplied callback function runs synchronously on the current tick to capture
its initial reactive dependency graph. If any tracked signal, collection, or reactive proxy property is mutated
subsequently, the effect is scheduled for re-execution in a batched microtask.
If the effect callback returns a cleanup function, it will be invoked immediately before the next execution and when the effect is explicitly disposed via the returned DisposeFn.
Example