Function leptos_reactive::store_value
source · pub fn store_value<T>(cx: Scope, value: T) -> StoredValue<T>where
T: 'static,
Expand description
Creates a non-reactive wrapper for any value by storing it within the reactive system.
Like the signal types (e.g., ReadSignal
and RwSignal), it is Copy
and 'static
. Unlike the signal
types, it is not reactive; accessing it does not cause effects to subscribe, and
updating it does not notify anything else.
ⓘ
// this structure is neither `Copy` nor `Clone`
pub struct MyUncloneableData {
pub value: String
}
// ❌ this won't compile, as it can't be cloned or copied into the closures
let data = MyUncloneableData { value: "a".into() };
let callback_a = move || data.value == "a";
let callback_b = move || data.value == "b";
// this structure is neither `Copy` nor `Clone`
pub struct MyUncloneableData {
pub value: String,
}
// ✅ you can move the `StoredValue` and access it with .with()
let data = store_value(cx, MyUncloneableData { value: "a".into() });
let callback_a = move || data.with(|data| data.value == "a");
let callback_b = move || data.with(|data| data.value == "b");