Reactive context; defaults to the shared global context.
Function that reads reactive properties and optionally returns a value.
Optionalsetter: (value: any) => void
Optional callback that receives the return value of getter, or its resolved value when getter returns a promise.
A disposal function that unsubscribes the effect from all tracked properties.
Creates a reactive effect that re-runs whenever tracked properties change.
The
getterfunction is executed immediately. Any property read on a signal during this execution is subscribed to the effect. When a subscribed property is written, the effect is scheduled to re-run (batched viasetTimeout(…, 0): one re-run per effect, however many of its properties were written in the meantime). An effect is not re-run by its own writes made during its getter, such as thelengththatpush()reads and then writes; a write to the same key from elsewhere in the same tick still re-runs it.An optional
setterreceives the return value ofgetter. When the getter returns aPromise,setteris called with its resolved value, unless the effect re-ran or was disposed in the meantime.An error thrown by
getteron the first run propagates to the caller and leaves the effect disposed. On a later run it unsubscribes the effect permanently, and an error thrown bysetteris kept from stopping the effect; both are reported throughreportError(orconsole.errorwhere it is unavailable) rather than thrown, so other effects of the same update still run. A promise that rejects is reported the same way, unless the effect re-ran or was disposed in the meantime, and the effect keeps running.The context is determined by
this, following the same rules as signal.