fermi.rs 542 B

123456789101112131415161718192021222324252627282930
  1. #![allow(non_snake_case)]
  2. use dioxus::prelude::*;
  3. use fermi::prelude::*;
  4. fn main() {
  5. dioxus::desktop::launch(app)
  6. }
  7. static NAME: Atom<String> = |_| "world".to_string();
  8. fn app(cx: Scope) -> Element {
  9. let name = use_read(&cx, NAME);
  10. cx.render(rsx! {
  11. div { "hello {name}!" }
  12. Child {}
  13. })
  14. }
  15. fn Child(cx: Scope) -> Element {
  16. let set_name = use_set(&cx, NAME);
  17. cx.render(rsx! {
  18. button {
  19. onclick: move |_| set_name("dioxus".to_string()),
  20. "reset name"
  21. }
  22. })
  23. }