dioxus-use-computed

Crates.iodioxus-use-computed
lib.rsdioxus-use-computed
version0.1.0
sourcesrc
created_at2024-06-24 15:13:15.887553
updated_at2024-06-24 15:13:15.887553
descriptionRun resource-expensive computations in the most efficient way possible in Dioxus 🧬 apps 🦀
homepagehttps://github.com/dioxus-community/dioxus-use-computed
repositoryhttps://github.com/dioxus-community/dioxus-use-computed
max_upload_size
id1282312
size108,360
Marc Espin (marc2332)

documentation

README

Discord Server

dioxus-use-computed 🦀🧠

Alternative to the built-in Dioxus hooks use_memo and use_reactive.

The main idea is to make resource-expensive computations in the most efficient way possible. Avoiding unnecessary rerenders and wrappers.

fn app() -> Element {
    let mut value = use_signal(|| 2);

    rsx!(
        Counter {
            value: value()
        }
        PrevCounter {
            value: value()
        }
        CounterSignal {
            value: value()
        }
        PrevCounterSignal {
            value: value()
        }
    )
}

#[component]
fn Counter(value: usize) -> Element {
    let double = use_computed(value, || value * 2);

    rsx!( p {  "Double: {double}" } )
}

#[component]
fn PrevCounter(value: usize) -> Element {
    let double = use_computed_with_prev(value, |prev_value| prev_value.unwrap_or(value) * 2);

    rsx!( p { "Previous Double: {double}" } )
}

#[component]
fn CounterSignal(value: usize) -> Element {
    let double = use_computed_signal(value, || value * 2);

    rsx!( p { "Double Signal: {double}" } )
}

#[component]
fn PrevCounterSignal(value: usize) -> Element {
    let double = use_computed_signal_with_prev(value, |prev| prev.cloned().unwrap_or(value) * 2);

    rsx!( p { "Previous Double Signal: {double}" } )
}
Commit count: 8

cargo fmt