Function freya::prelude::use_memo

pub fn use_memo<R>(f: impl FnMut() -> R + 'static) -> ReadOnlySignal<R>where
    R: PartialEq,
Expand description

Creates a new unsync Selector. The selector will be run immediately and whenever any signal it reads changes.

Selectors can be used to efficiently compute derived data from signals.

use dioxus::prelude::*;
use dioxus_signals::*;

fn App() -> Element {
    let mut count = use_signal(|| 0);
    let double = use_memo(move || count * 2);
    count += 1;
    assert_eq!(double.value(), count * 2);

    rsx! { "{double}" }
}