Function freya::prelude::use_tracked_state
pub fn use_tracked_state<T>(
cx: &ScopeState,
init: impl FnOnce() -> T
) -> &Tracked<T>where
T: 'static,
Expand description
Create a new tracked state. Tracked state is state that can drive Selector state
It state will efficiently update any Selector state that is reading from it, but it is not readable on it’s own.
use dioxus::prelude::*;
fn Parent(cx: Scope) -> Element {
let count = use_tracked_state(cx, || 0);
render! {
Child {
count: count.clone(),
}
}
}
#[inline_props]
fn Child(cx: Scope, count: Tracked<usize>) -> Element {
let less_than_five = use_selector(cx, count, |count| *count < 5);
render! {
"{less_than_five}"
}
}