Function freya::prelude::use_memo_with_dependencies
pub fn use_memo_with_dependencies<R, D>(
dependencies: D,
f: impl FnMut(<D as Dependency>::Out) -> R + 'static
) -> ReadOnlySignal<R>
Expand description
Creates a new unsync Selector with some local dependencies. The selector will be run immediately and whenever any signal it reads or any dependencies it tracks changes
Selectors can be used to efficiently compute derived data from signals.
use dioxus::prelude::*;
fn App() -> Element {
let mut local_state = use_signal(|| 0);
let double = use_memo_with_dependencies((&local_state(),), move |(local_state,)| local_state * 2);
local_state.set(1);
rsx! { "{double}" }
}