family.rs 1015 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. use std::collections::HashMap;
  2. use dioxus_core::prelude::*;
  3. use recoil::*;
  4. use uuid::Uuid;
  5. const TODOS: AtomFamily<Uuid, Todo> = |_| HashMap::new();
  6. #[derive(PartialEq)]
  7. struct Todo {
  8. checked: bool,
  9. title: String,
  10. contents: String,
  11. }
  12. static App: FC<()> = |ctx, _| {
  13. use_init_recoil_root(ctx, |_| {});
  14. let todos = use_read_family(ctx, &TODOS);
  15. rsx! { in ctx,
  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> = |ctx, props| {
  26. let (todo, set_todo) = use_read_write(ctx, &TODOS.select(&props.id));
  27. rsx! { in ctx,
  28. div {
  29. h1 {"{todo.title}"}
  30. input { type: "checkbox", name: "scales", checked: "{todo.checked}" }
  31. label { "{todo.contents}", for: "scales" }
  32. p {"{todo.contents}"}
  33. }
  34. }
  35. };
  36. fn main() {
  37. wasm_bindgen_futures::spawn_local(dioxus_web::WebsysRenderer::start(App))
  38. }