* Add some traits read only signal works with sync storage * seal gats * minimize diff
34 lines
739 B
Rust
34 lines
739 B
Rust
use dioxus::prelude::*;
|
|
|
|
fn main() {
|
|
dioxus::launch(app);
|
|
}
|
|
|
|
fn app() -> Element {
|
|
let mut store = use_hook(|| Store::new_maybe_sync(0u32));
|
|
|
|
rsx! {
|
|
button { onclick: move |_| store += 1, "Increase" }
|
|
"{store}"
|
|
Child { store }
|
|
}
|
|
}
|
|
|
|
#[component]
|
|
fn Child(store: WriteStore<u32, SyncStorage>) -> Element {
|
|
// A `WriteStore<T, SyncStorage>` can be sent to another thread!
|
|
// Make sure to clean up your threads when the component unmounts.
|
|
use_hook(|| {
|
|
std::thread::spawn(move || loop {
|
|
std::thread::sleep(std::time::Duration::from_secs(1));
|
|
store += 1;
|
|
|
|
if store() >= 10 {
|
|
break;
|
|
}
|
|
});
|
|
});
|
|
|
|
rsx! {}
|
|
}
|