dioxus/packages/atoms/_examples/familypoc.rs

48 lines
1 KiB
Rust
Raw Normal View History

2021-05-31 22:55:56 +00:00
use dioxus_core::prelude::*;
use im_rc::HashMap as ImMap;
use recoil::*;
use uuid::Uuid;
const TODOS: Atom<ImMap<Uuid, Todo>> = |_| ImMap::new();
#[derive(PartialEq)]
struct Todo {
checked: bool,
title: String,
contents: String,
}
2021-06-26 01:15:33 +00:00
static App: FC<()> = |cx| {
use_init_recoil_root(cx, |_| {});
let todos = use_read(&cx, &TODOS);
2021-05-31 22:55:56 +00:00
2021-06-26 01:15:33 +00:00
rsx! { in cx,
2021-05-31 22:55:56 +00:00
div {
"Basic Todolist with AtomFamilies in Recoil.rs"
}
}
};
#[derive(Props, PartialEq)]
struct ChildProps {
id: Uuid,
}
2021-06-26 01:15:33 +00:00
static Child: FC<ChildProps> = |cx| {
let todo = use_read(cx, &TODOS).get(&cx.id).unwrap();
// let (todo, set_todo) = use_read_write(cx, &TODOS);
2021-05-31 22:55:56 +00:00
2021-06-26 01:15:33 +00:00
rsx! { in cx,
2021-05-31 22:55:56 +00:00
div {
h1 {"{todo.title}"}
input { type: "checkbox", name: "scales", checked: "{todo.checked}" }
label { "{todo.contents}", for: "scales" }
p {"{todo.contents}"}
}
}
};
fn main() {
wasm_bindgen_futures::spawn_local(dioxus_web::WebsysRenderer::start(App))
}