davidmarsmalow's avatar

Livewire 4 @island inside a loop (foreach/forelse)

How to use @island inside a loop (@foreach / @forelse) in Livewire 4?

I’m experimenting with the new @island feature in Livewire 4, and I’m running into an issue when trying to use it inside a loop.

My use case is a Kanban-style board where columns are rendered dynamically using @foreach. Inside each column, I want to wrap part of the UI with @island so that it can be independently reactive.

Example

@foreach ($this->columns as $column)
    <flux:card>
        @island
            <livewire:wishlists.items
                :column-id="$column->id"
            />
        @endisland
    </flux:card>
@endforeach

The problem

Inside the @island, the $column variable (or $column->id) either:

  • is not available / becomes null, or
  • does not behave as expected when the loop updates
  • There is this error: Undefined variable $column

This raises a few questions:

  1. Does @island require all data to be passed explicitly via component properties?
  2. Is it expected that variables from a Blade loop (@foreach, @forelse) are not directly usable inside an island?
  3. Is there a recommended pattern for using @island inside loops? For example: using a wrapper Livewire component per iteration?

What I’m trying to achieve

  • Render multiple islands inside a loop
  • Each island should be scoped to its own column
  • Avoid unnecessary re-renders of other columns

Question

What is the correct or recommended way to use @island inside a loop in Livewire 4? Is this a limitation by design, or am I missing a required pattern?

Any guidance or examples would be greatly appreciated ⚡

0 likes
1 reply
DigitalArtisan's avatar

Islands can't be used in loops or conditionals:

Because islands don't have access to loop variables or conditional context, they cannot be used inside @foreach, @if, or other control structures:

Please or to participate in this conversation.