Support Ability To Extend Props From Other Props
Feature Request
It'd be helpful to have the ability to extend from another component's props:
#[derive(Props, Clone, PartialEq)]
pub struct Comp1Props {
abc: bool,
disabled: bool,
}
// .. fn Comp1()
#[derive(Props, Clone, PartialEq)]
pub struct Comp2Props {
// extend prop attributes by specifying component fn or prop struct
#[props(extends = Comp1)]
attributes: Vec<Attribute>,
}
#[component]
pub fn Comp2(props: Comp2Props) -> Element {
rsx! {
Comp1 {
disabled: false, // add your own props as desired
..props.attributes, // spread any generic prop through components
}
}
}
This looks similar to https://github.com/DioxusLabs/dioxus/issues/3844. The same structural typing approach I mentioned in that issue could allow spreading props of different types together
It might be a bit hack but I've used macro_magic for this type of thing. There's an example for merging structs. It's not the same as you've described because it actually includes the fields from the target struct, but it has worked for my library where I have a handful of common props I want included in every component. I'm also trying to use this to library to forward props to workaround the spreading limitation.