Skip to content

Commit

Permalink
Merge pull request #53 from marcorieser/support-component-key
Browse files Browse the repository at this point in the history
Support component key
  • Loading branch information
jonassiewertsen authored Mar 15, 2024
2 parents ecc3ac3 + 13972e2 commit 15bd037
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,22 @@ class ShowContact extends Component
}
```

The [Official Livewire documentation](https://livewire.laravel.com/docs/components#rendering-components)
The [Official Livewire documentation](https://livewire.laravel.com/docs/components#rendering-components) provides more information.

### Keying Components
Livewire components are automatically keyed by default. If you want to manually key a component, you can use the `key` attribute.
```html
<!-- If using Antlers -->
{{ contacts }}
{{ livewire:your-component-name :key="id" }}
{{ /contacts }}

<!-- If using Blade -->
@foreach ($contacts as $contact)
<livewire:your-component-name :key="$contact->id" />
@endforeach
```
The [Official Livewire documentation](https://livewire.laravel.com/docs/components#adding-wirekey-to-foreach-loops) provides more information.

### Multi-Site
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.
Expand Down
2 changes: 1 addition & 1 deletion src/Tags/Livewire.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Livewire extends Tags
*/
public function wildcard($expression): string
{
return \Livewire\Livewire::mount($expression, $this->params->toArray());
return \Livewire\Livewire::mount($expression, $this->params->except('key')->toArray(), $this->params->only('key')->first());
}

/**
Expand Down

0 comments on commit 15bd037

Please sign in to comment.