context.rs 474 B

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