Creates a reactive signal that holds a value and notifies dependents when the value changes.
Type:
Parameters:
value
: The initial value of the signalequals
: Optional custom equality comparator function to determine when the value has changed. Defaults to strict equality (===
)Returns: An array containing a getter function and a setter function
Getter<T>
: A function that returns the current value of the signalSetter<T>
: A function that accepts either a new value or a function that takes the previous value and returns a new valueExample:
Runs a function when dependencies change. Effects are batched and run after rendering, making them suitable for side effects that don't need to block the render cycle.
Type:
Parameters:
fn
: A function to run when dependencies change. It receives the previous value returned by the effect and returns a new value to be used in the next runvalue
: Optional initial value to pass to the first effect runExample:
Memoizes a value based on dependencies, only recalculating when dependencies change. Useful for expensive calculations that depend on reactive values.
Type:
Parameters:
fn
: A function that computes the memoized value. It receives the previous memoized value as an argumentvalue
: Optional initial valueequals
: Optional custom equality comparator function to determine when the computed value has changed. Defaults to strict equality (===
)Returns: A getter function that returns the memoized value
Example: