When I’m running the code below, everytime I click at the button the rendered data gets overridden.
Is it possible to add new items, without to lose the previous added data at the rerender?
With every click a new item should be added to create a list.
class Test extends Component
{
public $items = [];
public $key = 0;
public function add()
{
$this->key++;
$this->items = Arr::add(['name' => 'item'], 'key', $this->key);
}
public function render()
{
return view('livewire.ui.test');
}
}
blade:
<div>
@foreach($items as $item)
<div>{{ $item }}</div>
@endforeach
<button wire:click="add">test</button>
</div>