How to replace dyn child? #276
Replies: 1 comment
-
Okay, so I'm going to iterate through a few steps in order so you can see how I'd solve this.
icon_node = Some(Box::new(node));
Again, this makes sense: the type of icon_node = Some(Box::new(move |cx| node.into_view(cx)));
This one seems hard, but is easy. Instead of creating the icon_node = Some(Box::new(move |cx| {
view! {cx,
<Loading loading inherit_color=true/>
}
.into_view(cx)
}));
Specifically: component props are not reactive unless they are signal types. There's no magic happening at the component boundary that causes the component to react to changes in the values fed into its properties. Instead, the component function runs once and sets up a reactive UI. So unless I'm misunderstanding what you'd want to use this for, some of the fields—I'm thinking #[prop(into)]
loading: Signal<bool>, This means you can pass in a That would mean you could do something like // make it a closure so `icon_node` is reactive
let icon_node = move || {
// because loading is a Signal now, call it
if loading() {
Some(view! { cx, <Loading loading inherit_color=true/> }.into_view(cx))
} else {
icon.map(|icon| icon(cx))
}
}; |
Beta Was this translation helpful? Give feedback.
-
The code "icon_node = Some(Box(node));" is error:error[E0423]: cannot initialize a tuple struct which contains private fields
And the code as the following:
Beta Was this translation helpful? Give feedback.
All reactions