← All news

Default Props

v0.7.6 adds support for the Default trait in component syntax, letting you omit props that have sensible defaults.

The .. syntax

When a component struct derives or implements Default, you can now use .. after any explicit props to fill the remaining fields with their default values — identical to Rust's struct update syntax:

1#[derive(Default)]
2pub struct Alert {
3 pub message: String,
4 pub kind: AlertKind, // defaults to AlertKind::Info
5 pub dismissible: bool, // defaults to false
6}
7
8// Only set what you care about
9view! {
10 <Alert message={"Saved!".into()} .. />
11}

The .. shorthand must appear after all explicit props and before the closing />

Useful for configuration components

This pattern works well for components with many optional settings, such as modals, toasts, tables, or form inputs. Define your defaults once on the struct, and callers only need to specify what differs:

1#[derive(Default)]
2pub struct DataTable {
3 pub rows: Vec<Row>,
4 pub striped: bool, // false
5 pub bordered: bool, // false
6 pub page_size: usize, // 0 = show all
7}
8
9view! {
10 // Use all defaults except rows
11 <DataTable rows={data} .. />
12
13 // Override a couple of options
14 <DataTable rows={data} striped={true} page_size={25} .. />
15}

Upgrading

No breaking changes. Update your dependency and derive Default on any component struct you want to use the shorthand with:

1[dependencies]
2tidos = "0.7.6"