use_memo
Creates a memoized computed value with automatic dependency tracking. The value is only recomputed when reactive dependencies change.Signature
Parameters
Computation function that returns the derived value. This function is called initially and whenever any reactive values (signals, memos, etc.) read inside the function change.
Type Constraints
The return type must implement
PartialEq to determine if the computed value has changed. If the computed value is equal to the previous value, subscribers won’t be notified.Returns
A copyable memo handle that can be read like a signal. Reading from the memo subscribes the current component to updates.
Description
Memos are for computing derived state from signals or other reactive values. They automatically track dependencies and only recompute when those dependencies change. Key characteristics:- Cached: The computed value is cached and only recomputed when dependencies change
- Compared: New values are compared with
PartialEq- components only re-render if the value actually changes - Reactive: Reading from a memo subscribes components to updates, just like signals
- Copy: Memos implement
Copyand can be freely passed around
Example
Compute full name from first and last name:Example: Expensive computation
Memoize expensive filtering operation:Related
use_signal- Create reactive stateuse_resource- Async memoized computationsuse_effect- Run side effects instead of computing values