context.rs 522 B

123456789101112131415161718192021
  1. #![allow(non_snake_case)]
  2. use dioxus::prelude::*;
  3. use dioxus_signals::Signal;
  4. fn main() {
  5. // dioxus_desktop::launch(app);
  6. }
  7. // Because signal is never read in this component, this component will not rerun when the signal changes
  8. fn app() -> Element {
  9. use_context_provider(|| Signal::new(0));
  10. rsx! { Child {} }
  11. }
  12. // This component does read from the signal, so when the signal changes it will rerun
  13. #[component]
  14. fn Child() -> Element {
  15. let signal: Signal<i32> = use_context();
  16. rsx! { "{signal}" }
  17. }