Skip to content
This repository was archived by the owner on Jan 27, 2025. It is now read-only.

Commit 15bd037

Browse files
Merge pull request #53 from marcorieser/support-component-key
Support component key
2 parents ecc3ac3 + 13972e2 commit 15bd037

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,22 @@ class ShowContact extends Component
119119
}
120120
```
121121

122-
The [Official Livewire documentation](https://livewire.laravel.com/docs/components#rendering-components)
122+
The [Official Livewire documentation](https://livewire.laravel.com/docs/components#rendering-components) provides more information.
123+
124+
### Keying Components
125+
Livewire components are automatically keyed by default. If you want to manually key a component, you can use the `key` attribute.
126+
```html
127+
<!-- If using Antlers -->
128+
{{ contacts }}
129+
{{ livewire:your-component-name :key="id" }}
130+
{{ /contacts }}
131+
132+
<!-- If using Blade -->
133+
@foreach ($contacts as $contact)
134+
<livewire:your-component-name :key="$contact->id" />
135+
@endforeach
136+
```
137+
The [Official Livewire documentation](https://livewire.laravel.com/docs/components#adding-wirekey-to-foreach-loops) provides more information.
123138

124139
### Multi-Site
125140
When using Livewire in a Multi-Site context, the current site gets lost between requests. There is a trait (`\Jonassiewertsen\Livewire\RestoreCurrentSite`) to solve that. Just include it in your component and use `Site::current()` as you normally do.

src/Tags/Livewire.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Livewire extends Tags
1313
*/
1414
public function wildcard($expression): string
1515
{
16-
return \Livewire\Livewire::mount($expression, $this->params->toArray());
16+
return \Livewire\Livewire::mount($expression, $this->params->except('key')->toArray(), $this->params->only('key')->first());
1717
}
1818

1919
/**

0 commit comments

Comments
 (0)