-
Notifications
You must be signed in to change notification settings - Fork 22
Closed
Description
Say I have a component with optional fields:
#[component]
fn input<'a>(name: &'a str, value: Option<&'a str>, error: Option<&'a str>, max_length: u8, ...) -> impl Renderable {
...
}It's tedious to enter values of all fields (rsx syntax) each time I use this component.
<Input name="email" value=None error=None max_length=32 ...>I would like to propose a way to set default values for each attribute. The syntax could look like this:
#[component]
fn input<'a>(
name: &'a str,
#[default] value: Option<&'a str>,
#[default] error: Option<&'a str>,
#[default(32)] max_length: u8,
...
) -> impl Renderable {
...
}#[default] uses the Default trait to get the value. You can also specify a value using #[default(value)].
Then you can just use Input component without repetition. You can only specify the attributes you want to override.
<Input name="email" value=(Some("John"))>What do you think?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels