Files
dioxus/packages/signals/examples/send_store.rs
T
Evan Almloff da32278b3a Sync ReadSignal and Store (#4608)
* Add some traits read only signal works with sync storage

* seal gats

* minimize diff
2025-10-03 20:05:43 -07:00

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! {}
}