mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-12-18 08:33:07 +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.
41 lines
748 B
Rust
41 lines
748 B
Rust
use dioxus_core::debug_renderer::DebugRenderer;
|
|
use dioxus_core::{component::Properties, prelude::*};
|
|
|
|
fn main() -> Result<(), ()> {
|
|
let p1 = SomeProps { name: "bob".into() };
|
|
|
|
let _vdom = DebugRenderer::new_with_props(Example, p1);
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[derive(Debug, PartialEq, Props)]
|
|
struct SomeProps {
|
|
name: String,
|
|
}
|
|
|
|
static Example: FC<SomeProps> = |ctx| {
|
|
ctx.render(html! {
|
|
<div>
|
|
<h1> "hello world!" </h1>
|
|
</div>
|
|
})
|
|
};
|
|
|
|
// #[test]
|
|
#[derive(PartialEq, Clone)]
|
|
struct MyStruct {
|
|
a: String,
|
|
}
|
|
|
|
fn check_before_to_owned() {
|
|
let new_str = MyStruct {
|
|
a: "asd".to_string(),
|
|
};
|
|
|
|
let out = town(&new_str);
|
|
}
|
|
|
|
fn town<T: ToOwned + PartialEq>(t: &T) -> T::Owned {
|
|
t.to_owned()
|
|
}
|