#Extend attributes compile error

1 messages · Page 1 of 1 (latest)

pure holly
#

I'm trying to make button components like so:

#[component]
pub fn Button(
    on_click: EventHandler,
    children: Element,
    #[props(extends = button)] attributes: Vec<Attribute>,
) -> Element {
    rsx! {
        button {
            onclick: move |_| on_click.call(()),
            class: "cursor-pointer rounded-xl px-4 py-2 font-bold",
            ..attributes,
            {children}
        }
    }
}

#[component]
pub fn PrimaryButton(
    on_click: EventHandler,
    #[props(extends = Button)] attributes: Vec<Attribute>,
    children: Element,
) -> Element {
    rsx! {
        Button {
            on_click,
            class: "bg-accent-300 hover:bg-accent-400",
            ..attributes,
            {children}
        }
    }
}

but this is failing with

no method named into_vcomponent found for struct std::vec::Vec<dioxus::prelude::Attribute> in the current scope
method not found in std::vec::Vec<dioxus::prelude::Attribute> (rustc E0599)

I don't understand why this doesn't work, anyone know why this might happen?

lone pendant
#

Spreading works differently for components than elements

#

For components, spreading is type checked so you can spread ButtonProps into Button, but not attributes