selectorlist.rs 847 B

1234567891011121314151617181920212223242526272829303132333435
  1. use std::collections::HashMap;
  2. use dioxus_core::prelude::*;
  3. use recoil::*;
  4. const A_ITEMS: AtomFamily<i32, i32> = |_| HashMap::new();
  5. const B_ITEMS: AtomFamily<i32, i32> = |_| HashMap::new();
  6. const C_SELECTOR: SelectorFamily<i32, i32> = |api, key| {
  7. let a = api.get(&A_ITEMS.select(&key));
  8. let b = api.get(&B_ITEMS.select(&key));
  9. a + b
  10. };
  11. const D_SELECTOR: SelectorFamilyBorrowed<i32, i32> = |api, key| -> &i32 {
  12. let a = api.get(&A_ITEMS.select(&key));
  13. a
  14. };
  15. static App: FC<()> = |ctx, _| {
  16. use_init_recoil_root(ctx);
  17. let title = use_recoil_value(ctx, &C_SELECTOR);
  18. let title = "";
  19. rsx! { in ctx,
  20. div {
  21. "{title}"
  22. // button { onclick: {next_light}, "Next light" }
  23. }
  24. }
  25. };
  26. fn main() {
  27. wasm_bindgen_futures::spawn_local(dioxus_web::WebsysRenderer::start(App))
  28. }