dioxus/packages/signals/examples/context.rs

26 lines
551 B
Rust
Raw Normal View History

2023-08-08 01:20:03 +00:00
#![allow(non_snake_case)]
use dioxus::prelude::*;
2023-08-08 18:12:08 +00:00
use dioxus_signals::Signal;
2023-08-08 01:20:03 +00:00
fn main() {
dioxus_desktop::launch(app);
}
fn app() -> Element {
2023-08-08 01:20:03 +00:00
// Because signal is never read in this component, this component will not rerun when the signal changes
use_context_provider(|| Signal::new(0));
2023-08-08 01:20:03 +00:00
2024-01-16 19:18:46 +00:00
rsx! {
2023-08-08 01:20:03 +00:00
Child {}
}
}
fn Child() -> Element {
2023-08-08 01:20:03 +00:00
let signal: Signal<i32> = *use_context(cx).unwrap();
// This component does read from the signal, so when the signal changes it will rerun
2024-01-16 19:18:46 +00:00
rsx! {
2023-08-08 01:20:03 +00:00
"{signal}"
}
}