family.rs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. use std::{collections::HashMap, rc::Rc};
  2. use dioxus_core::prelude::*;
  3. use recoil::*;
  4. use uuid::Uuid;
  5. const TODOS: AtomHashMap<Uuid, Rc<Todo>> = |map| {};
  6. #[derive(PartialEq)]
  7. struct Todo {
  8. checked: bool,
  9. title: String,
  10. content: String,
  11. }
  12. static App: FC<()> = |cx| {
  13. use_init_recoil_root(cx, move |cfg| {});
  14. let todos = use_read_family(cx, &TODOS);
  15. // rsx! { in cx,
  16. // div {
  17. // h1 {"Basic Todolist with AtomFamilies in Recoil.rs"}
  18. // ul { { todos.keys().map(|id| rsx! { Child { id: *id } }) } }
  19. // }
  20. // }
  21. cx.render(html! {
  22. <a href="#" class="">
  23. <img class="inline-block h-10 w-10 rounded-full object-cover ring-2 ring-white" src="/images/person/4.jpg" alt="Jade"/>
  24. </a>
  25. })
  26. };
  27. #[derive(Props, PartialEq)]
  28. struct ChildProps {
  29. id: Uuid,
  30. }
  31. static Child: FC<ChildProps> = |cx| {
  32. let (todo, set_todo) = use_read_write(cx, &TODOS.select(&cx.id));
  33. rsx! { in cx,
  34. li {
  35. h1 {"{todo.title}"}
  36. input { type: "checkbox", name: "scales", checked: "{todo.checked}" }
  37. label { "{todo.content}", for: "scales" }
  38. p {"{todo.content}"}
  39. }
  40. }
  41. };
  42. fn main() {
  43. wasm_bindgen_futures::spawn_local(dioxus_web::WebsysRenderer::start(App))
  44. }