mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-12-24 19:43:10 +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.
46 lines
1.8 KiB
Rust
46 lines
1.8 KiB
Rust
use dioxus::{events::on::MouseEvent, prelude::*};
|
|
use dioxus_core as dioxus;
|
|
use dioxus_web::WebsysRenderer;
|
|
|
|
fn main() {
|
|
wasm_logger::init(wasm_logger::Config::new(log::Level::Debug));
|
|
console_error_panic_hook::set_once();
|
|
wasm_bindgen_futures::spawn_local(WebsysRenderer::start(App));
|
|
}
|
|
|
|
fn App(ctx: Context<()>) -> VNode {
|
|
let cansee = use_state_new(&ctx, || false);
|
|
rsx! { in ctx,
|
|
div {
|
|
"Shadow of the child:"
|
|
button {
|
|
"Gaze into the void"
|
|
onclick: move |_| cansee.set(!**cansee)
|
|
}
|
|
{cansee.then(|| rsx!{ Child {} })}
|
|
}
|
|
}
|
|
}
|
|
|
|
fn Child(ctx: Context<()>) -> VNode {
|
|
rsx! { in ctx,
|
|
section { class: "py-6 bg-coolGray-100 text-coolGray-900"
|
|
div { class: "container mx-auto flex flex-col items-center justify-center p-4 space-y-8 md:p-10 md:px-24 xl:px-48"
|
|
h1 { class: "text-5xl font-bold leading-none text-center",
|
|
"Sign up now"
|
|
}
|
|
p { class: "text-xl font-medium text-center",
|
|
"At a assumenda quas cum earum ut itaque commodi saepe rem aspernatur quam natus quis nihil quod, hic explicabo doloribus magnam neque, exercitationem eius sunt!"
|
|
}
|
|
div { class: "flex flex-col space-y-4 sm:space-y-0 sm:flex-row sm:space-x-8"
|
|
button { class: "px-8 py-3 text-lg font-semibold rounded bg-violet-600 text-coolGray-50",
|
|
"Get started"
|
|
}
|
|
button { class: "px-8 py-3 text-lg font-normal border rounded bg-coolGray-800 text-coolGray-50 border-coolGray-700",
|
|
"Learn more"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|