-
Dear Leptos Team, I'm facing an issue where a component loses interactivity when rendered as an #[component]
fn Counter(initial_value: i32) -> impl IntoView {
let (value, set_value) = signal(initial_value);
view! {
<div>
<button
class="bg-amber-300 hover:bg-amber-100 text-gray-900 font-bold py-2 px-4 rounded transition duration-300 ease-in-out cursor-pointer"
on:click=move |_| set_value.update(|value| *value -= 1)
>
"-1"
</button>
<span class="text-gray-50 text-xl">
"Value: " {move || value.get().to_string()} "!"
</span>
<button
class="bg-amber-300 hover:bg-amber-100 text-gray-900 font-bold py-2 px-4 rounded transition duration-300 ease-in-out cursor-pointer"
on:click=move |_| set_value.update(|value| *value += 1)
>
"+1"
</button>
</div>
}
}
#[component]
fn HomePage() -> impl IntoView {
let counter_rendered = view! { <Counter initial_value=4 /> };
let mut string_components = "<Counter />".to_string();
if cfg!(feature = "ssr") {
string_components = string_components.replace("<Counter />", &counter_rendered.to_html());
}
view! {
<section>
<article>
<div inner_html=string_components />
</article>
</section>
}
} The I'm using the Axum + Leptos template with Leptos version Best regards, Victor Ferreira da Silva |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
You're right, that absolutely won't work. I'm not entirely sure what you're trying to accomplish here/why it can't be done with the normal APIs, but perhaps it's distilled from an example that makes more sense. I'm not sure I understand why the example above isn't this: #[component]
fn HomePage() -> impl IntoView {
view! {
<section>
<article>
<div><Counter initial_value=4 /></div>
</article>
</section>
}
} I'm happy to try to help if you can provide more details about what you're trying to do. |
Beta Was this translation helpful? Give feedback.
Oh yeah, that's quite interesting. It seems to me that what they're doing would be expressed in Rust terms by a proc macro that could parse Markdown and also Leptos's
view
syntax, and would transform the Markdown into the same builder-syntax output that the view macro uses.There's been some discussion but I don't think anyone's made an up-to-date library to do this. (It can be done entirely in user-land, and doesn't need explicit framework support.)