context.rs 579 B

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