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 will efficiently update any Selector state that is reading from it, but it is not readable on its own.

use dioxus::prelude::*;

#[component]
fn Parent(cx: Scope) -> Element {
   let count = use_tracked_state(cx, || 0);

   render! {
       Child {
           count: count.clone(),
       }
   }
}

#[component]
fn Child(cx: Scope, count: Tracked<usize>) -> Element {
   let less_than_five = use_selector(cx, count, |count| *count < 5);

   render! {
       "{less_than_five}"
   }
}