familypoc.rs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. use dioxus_core::prelude::*;
  2. use im_rc::HashMap as ImMap;
  3. use recoil::*;
  4. use uuid::Uuid;
  5. const TODOS: Atom<ImMap<Uuid, Todo>> = |_| ImMap::new();
  6. #[derive(PartialEq)]
  7. struct Todo {
  8. checked: bool,
  9. title: String,
  10. contents: String,
  11. }
  12. static App: FC<()> = |cx| {
  13. use_init_recoil_root(cx, |_| {});
  14. let todos = use_read(&cx, &TODOS);
  15. rsx! { in cx,
  16. div {
  17. "Basic Todolist with AtomFamilies in Recoil.rs"
  18. }
  19. }
  20. };
  21. #[derive(Props, PartialEq)]
  22. struct ChildProps {
  23. id: Uuid,
  24. }
  25. static Child: FC<ChildProps> = |cx| {
  26. let todo = use_read(cx, &TODOS).get(&cx.id).unwrap();
  27. // let (todo, set_todo) = use_read_write(cx, &TODOS);
  28. rsx! { in cx,
  29. div {
  30. h1 {"{todo.title}"}
  31. input { type: "checkbox", name: "scales", checked: "{todo.checked}" }
  32. label { "{todo.contents}", for: "scales" }
  33. p {"{todo.contents}"}
  34. }
  35. }
  36. };
  37. fn main() {
  38. wasm_bindgen_futures::spawn_local(dioxus_web::WebsysRenderer::start(App))
  39. }