docsite
docsite copied to clipboard
Attribute spreading (`..props.attributes` syntax) is not documented
Attribute "spreading" (I wish we could find a new name for this.. 😅) is the process of assigning properties from a "catch-all" collection.
This is very useful for developing reusable components, but it's completely missing from the docsite.
Here's an example, adapted from https://github.com/DioxusLabs/dioxus/issues/3844:
#[derive(Props, PartialEq, Debug, Clone)]
pub struct ChildProps {
#[props(extends = button, extends = GlobalAttributes)]
pub attributes: Vec<Attribute>,
#[props(optional, default = None)]
pub children: Element,
}
#[component]
pub fn Child(props: ChildProps) -> Element {
rsx! {
button {
..props.attributes,
{props.children}
}
}
}
#[component]
pub fn Hero() -> Element {
rsx! {
Child {
class: "hard-to-miss",
style: "border: 1px solid lime;",
"Content here..",
}
}
}
It would be very nice to have this feature mentioned in the documentation.
This is now mentioned briefly here with a link to more info on docs.rs