computed!() { /* proc-macro */ }Expand description
The computed! macro for creating reactive computed signals.
Watches one or more signals and derives a new signal whose value is automatically computed from the closure return value whenever any input signal changes. The closure must return a value of the specified return type.
The number of signal expressions must match the number of closure parameters.
Each closure parameter receives the current value (via .get()) of the
corresponding signal. Parameter types are optional and can be annotated
after a colon. The return type must be specified after ->.
The result signal is created via use_signal and updated via set_silent
to avoid cascading re-renders. The initial value is computed immediately
during first render.
ⓘ
let first_name = use_signal(|| String::from("John"));
let last_name = use_signal(|| String::from("Doe"));
let full_name: Signal<String> = computed!(first_name, last_name, |first: String, last: String| -> String {
format!("{} {}", first, last)
});