Crates.io | dioxus-use-computed |
lib.rs | dioxus-use-computed |
version | |
source | src |
created_at | 2024-06-24 15:13:15.887553+00 |
updated_at | 2024-12-10 10:36:49.857197+00 |
description | Run resource-expensive computations in the most efficient way possible in Dioxus 🧬 apps 🦀 |
homepage | https://github.com/dioxus-community/dioxus-use-computed |
repository | https://github.com/dioxus-community/dioxus-use-computed |
max_upload_size | |
id | 1282312 |
Cargo.toml error: | TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
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}" } )
}