mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-12-27 04:53:12 +00:00
508c560320
This change switches back to the original `ctx<props>` syntax for commponents. This lets lifetime elision to remove the need to match exactly which lifetime (props or ctx) gets carried to the output. As such, `Props` is currently required to be static. It *is* possible to loosen this restriction, and will be done in the future, though only through adding metadata about the props through the Props derive macro. Implementing the IS_STATIC trait is unsafe, so the derive macro will do it through some heuristics. For now, this unlocks sharing vnodes from parents to children, enabling pass-thru components, fragments, portals, etc.
47 lines
1 KiB
Rust
47 lines
1 KiB
Rust
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,
|
|
}
|
|
|
|
static App: FC<()> = |ctx| {
|
|
use_init_recoil_root(ctx, |_| {});
|
|
let todos = use_read(ctx, &TODOS);
|
|
|
|
rsx! { in ctx,
|
|
div {
|
|
"Basic Todolist with AtomFamilies in Recoil.rs"
|
|
}
|
|
}
|
|
};
|
|
|
|
#[derive(Props, PartialEq)]
|
|
struct ChildProps {
|
|
id: Uuid,
|
|
}
|
|
|
|
static Child: FC<ChildProps> = |ctx| {
|
|
let todo = use_read(ctx, &TODOS).get(&ctx.id).unwrap();
|
|
// let (todo, set_todo) = use_read_write(ctx, &TODOS);
|
|
|
|
rsx! { in ctx,
|
|
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))
|
|
}
|