-
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Few questions on usage #29
Comments
#[component]
pub fn Entry<'a>(props: &mut EntryProps<'a>) -> impl Into<AnyElement<'a>> {
element! {
Box {
Box(margin_right: 1) {
Text(content: format!("{}:", props.title))
}
Box {
#(&mut props.children)
}
}
}
}
#[derive(Default, Props)]
pub struct ExampleProps<'a> {
pub my_child: Option<AnyElement<'a>>,
}
#[component]
fn Example<'a>(props: &mut ExampleProps<'a>) -> impl Into<AnyElement<'a>> {
element! {
Box {
#(&mut props.my_child)
}
}
}
fn main() {
element! {
Example(my_child: element! {
Text(content: "foo")
}.into_any())
}
.print();
} Or alternatively, if you want to avoid nesting, you can define the child beforehand: fn main() {
let my_child = element! {
Text(content: "foo")
}
.into_any();
element! {
Example(my_child)
}
.print();
} |
Awesome, got these working, thank you! It would be great of their was an example file with all the different ways things can be done in regards to the syntax. |
For convenience, it would be nice to maybe offer an |
Another suggestion, rename |
In hindsight I wish I had done this from the start. But as this would undoubtedly break every program using the library, I would want to wait until I have other big breaking changes to release before making a change like this. |
@ccbrown Just have a few questions so far that I haven't been able to figure out.
1 - How to pass children through for custom components? Maybe we need a
Fragment
component here?2 - Is it possible to render components as props to other components? Or is it only possible with children?
The text was updated successfully, but these errors were encountered: