Function leptos::create_rw_signal

source ·
pub fn create_rw_signal<T>(cx: Scope, value: T) -> RwSignal<T>
Expand description

Creates a reactive signal with the getter and setter unified in one value. You may prefer this style, or it may be easier to pass around in a context or as a function argument.

let count = create_rw_signal(cx, 0);

// ✅ set the value
count.set(1);
assert_eq!(count(), 1);

// ❌ don't try to call the getter within the setter
// count.set(count.get() + 1);

// ✅ instead, use .update() to mutate the value in place
count.update(|count: &mut i32| *count += 1);
assert_eq!(count(), 2);