Skip to main content

LivewireComponent

Derive Macro LivewireComponent 

Source
#[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:

AttributeMeaning
skipNever crosses the wire; keeps its default
lockedCrosses the wire, but the browser may not change it
modelableA parent may bind it with wire:model
reactiveA parent’s change resets the component
synth(path::to::Synth)A synthesizer reads and writes it
formA 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