Creates a reactive computation that runs immediately and re-executes when dependencies change. The function receives its previous return value and is designed for side effects that update reactive state. Unlike useMemo
, it doesn't return a value, and unlike useEffect
, it runs synchronously during rendering, which may cause excessive updates.
Type:
Parameters:
fn
: A function that computes the derived value. It receives the previous computed value as an argumentvalue
: Optional initial valueExample:
Creates a render effect that runs synchronously during rendering, before DOM updates complete. Unlike useEffect
, it executes immediately when DOM elements may not be ready and refs aren't set. Reactive updates are batched automatically.
Type:
Parameters:
fn
: A function that executes synchronously during rendering, receiving the previous return valuevalue
: Optional initial valueExample:
Creates an optimized conditional selector that efficiently manages subscriptions by only notifying subscribers when their specific key starts or stops matching the source value. This optimization drastically improves update performance by minimizing the number of subscribers that need to be notified when the source value changes.
Type:
Parameters:
source
: A getter function that returns the source value to compare against keysfn
: Optional custom equality function that receives a key and the source value, returning whether they should be treated as equal. Defaults to strict equality (===
)Returns: A function that takes a key and returns whether it matches the current source value
Example: