-
I read [https://leptos-rs.github.io/leptos/view/06_control_flow.html](Control Flow) chapter from the book but could not implement something that compiles. Is there a way to do something like this?
Basically, I will render content 100% but might wrap it or not. And content potentially might be bigger than a simple string thus, want to avoid manually inlining it (What I am am currently doing) Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It would be helpful to see an example of your actual code that doesn't compile, and to know what the compile errors are. What you're trying to do is perfectly achievable; here would be one example that does compile: #[component]
pub fn Logo(#[prop(optional)] href: Option<&'static str>) -> impl IntoView {
let content = view! { <p>"ok"</p> };
move || match href {
Some(href) => {
let content = content.clone();
view! {
<A href={href}>{content}</A>
};
}
.into_view(),
None => content.clone().into_view(),
}
} Note, by the way, that several of your |
Beta Was this translation helpful? Give feedback.
It would be helpful to see an example of your actual code that doesn't compile, and to know what the compile errors are. What you're trying to do is perfectly achievable; here would be one example that does compile:
Note, by the way, that several of your
view!
invocations are unnecessary: themove || match
…