Repository navigation
String does not implement Properties
#3853
LucaCappelletti94
started this conversation in
Ideas
Replies: 2 comments 4 replies
|
#[derive(PartialEq, Properties,)]
pub struct FaIconProps {
icon: String,
}
/// Renders a Font Awesome icon.
#[function_component]
pub fn FAIcon(FaIconProps { icon }: &FaIconProps) -> Html {
// ^------------------^ note that we can pattern match the struct away in the argument
html! {
<i class={format!("fa-solid fa-{}", icon)} aria-hidden="true"></i>
}
}
// Later
<FAIcon icon="web-awesome" />In case you don't want or need to write the struct by hand, there's |
1 reply
|
From an ergonomics perspective, I imagine people will need to add more and more non-primitive props to the component and end up having to create a struct? Is it possible to have multiple props like this? #[derive(Properties, PartialEq)]
struct TitileExtraProps{
// ...
}
#[function_component]
fn Title(title: &String, extra_props: &TitileExtraProps) -> Html {
html! { <h1>{ title }</h1> }
}I wonder if it's a good idea to make |
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
At this time, it appears that the
Propertiestrait is not implemented for several std types, such asString:It would be quite handy to have it, as in several instances I have simple component which receive a single attribute as input, such as the following one:
I will try to make a PR adding this - I am unsure whether there are strong reasons for this type not being supported.
All reactions