leptos
leptos copied to clipboard
Spreading a dynamic list of attributes on a component
Describe the bug Not entirely sure if this is a bug or a feature request, but I would like to be able to spread a dynamic list of attributes to a component.
Leptos Dependencies
leptos = { version = "0.6", features = ["nightly"] }
leptos_axum = { version = "0.6", optional = true }
leptos_meta = { version = "0.6", features = ["nightly"] }
leptos_router = { version = "0.6", features = ["nightly"] }
To Reproduce
#[component]
fn Comp1() -> impl IntoView {
let attrs = vec![("id", Attribute::String("1".into()))];
view! {
<>
// this works (id is set to 1)
<div {..attrs}>Hello</div>
// this doesn't work (no id is set)
<Comp2 {..attrs}/>
// this does work
<Comp2 attr:test=5/>
</>
}
}
#[component]
fn Comp2(#[prop(attrs)] attrs: Vec<(&'static str, Attribute)>) -> impl IntoView {
let attrs_len = attrs.len();
view! { <div {..attrs}>{attrs_len}</div> }
}
Expected behavior
I would expect that Comp2 renders into <div id="1">1</div>, but instead it renders to <div>0</div>.
i've got a working solution for this, but my fork also includes a way to spread things other than attributes which https://github.com/leptos-rs/leptos/pull/2432 seems to have beaten me to
so if/when it gets merged i'll adapt it to that
i've got a working solution for this, but my fork also includes a way to spread things other than attributes which #2432 seems to have beaten me to
so if/when it gets merged i'll adapt it to that
Very cool, thanks for your contributions : )