use_effect
Run side effects with automatic dependency tracking. The effect automatically re-runs when any signal or reactive value read inside the effect changes.Signature
Parameters
The effect function to run. This function is called immediately when the component mounts, and again whenever any reactive values (signals, memos, etc.) read inside the effect change.
Returns
A handle to the effect that can be used to manually trigger re-runs via
mark_dirty().Description
Effects are used for side effects that need to react to state changes. The effect function runs:- Once immediately when the component first renders
- Whenever any reactive value read inside the effect changes
- When manually triggered via
Effect::mark_dirty()
Example
Log to console whenever count changes:Example: External API synchronization
Sync with local storage:Related
use_memo- Compute derived values instead of side effectsuse_resource- Async effects that return a valueuse_signal- Create reactive state