selectorlist.rs 816 B

12345678910111213141516171819202122232425262728293031323334
  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. let title = use_recoil_value(ctx, &C_SELECTOR);
  17. let title = "";
  18. rsx! { in ctx,
  19. div {
  20. "{title}"
  21. // button { onclick: {next_light}, "Next light" }
  22. }
  23. }
  24. };
  25. fn main() {
  26. wasm_bindgen_futures::spawn_local(dioxus_web::WebsysRenderer::start(App))
  27. }