selectorlist.rs 827 B

1234567891011121314151617181920212223242526272829303132333435
  1. use std::collections::HashMap;
  2. use dioxus_core::prelude::*;
  3. use recoil::*;
  4. const A_ITEMS: AtomHashMap<i32, i32> = |_| HashMap::new();
  5. const B_ITEMS: AtomHashMap<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_read(ctx, &C_SELECTOR);
  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. }