#[derive(LivewireComponent)]
{
// Attributes available to this derive:
#[livewire]
}
Expand description
Makes a struct a Livewire component’s state: its wire-public fields, their rules, and the view it renders by default.
ⓘ
#[derive(Default, LivewireComponent)]
#[livewire(view = "livewire.counter")]
struct Counter {
count: i32,
#[livewire(locked)]
id: String,
#[livewire(skip)]
cache: Vec<String>,
}The struct must implement Default, because a later request rebuilds it from its snapshot and
then reads the fields the snapshot holds.
Field attributes:
| Attribute | Meaning |
|---|---|
skip | Never crosses the wire; keeps its default |
locked | Crosses the wire, but the browser may not change it |
modelable | A parent may bind it with wire:model |
reactive | A parent’s change resets the component |
synth(path::to::Synth) | A synthesizer reads and writes it |
form | A struct of wire-public fields crosses the wire as one object |
url / url(as = "q", use = "replace", always_show = true, except = "a") | Follows the query string |
session / session(key = "component-key") | Persists in the session |
validate(required, max_length(255)) | Validation rules |