It helps Livewire track DOM elements correctly during updates, preventing state mixups and improving performance.
Essential for places where the same livewire component is included multiple times, like @foreach statements.
Add to the root element inside loops, or any element that needs unique identification across renders.
Use wire:key="unique-identifier" with stable values like entity IDs. Ex: wire:key="todo-{{$todo['id']}}"
Click on each example to see live demo:
BROKEN
DOM state gets mixed up when reordering items. Input values stick to wrong positions.
CORRECT
Stable keys using todo ID preserve DOM state correctly. Input values move with their items.
WORST
Using rand() causes complete DOM regeneration. Every action scrambles input values.
Click on each example to see live demo:
BROKEN COMMUNICATION
Child sends events to parent, but random keys cause component re-initialization and console errors on button clicks.
WORKING CORRECTLY
Livewire keeps track of the component. Child-to-parent communication works flawlessly with no console errors.
Do your part, stop using random keys!
Random keys break component state and cause unnecessary re-renders. Use stable, meaningful identifiers instead.
Migration Impact: The Livewire 3 migration is made harder by these random keys, as each one needs to be analyzed and replaced manually.
Note: The collected statistics might not be 100% accurate because aico includes legacy/unused pages that are still tracked in the repository.