I have 2 components, CastComparer and CastSearch. CastSearch are nested components within CastComparer.
Upon a certain action, the CastSearch component emits an event which CastComparer is listening for, called compare
I emit this event by doing $this->emit('compare', $this->selected);
This calls a function on my CastComparer component called makeComparison().
Below is my CastComparer component class
class CastComparer extends Component
{
public $cast_members = [];
protected $listeners = ['compare' => 'makeComparison'];
public function render()
{
return view('livewire.cast-comparer');
}
public function makeComparison($id)
{
array_push($this->cast_members, $id);
dd($this->cast_members);
}
}
The issue I am having is, each time this is called the $cast_members array gets reset. So for example if 5 of my CastSearch components all emitted, i’d expect $cast_members array to have this
["test0", "test1", "test2", "test3", "test4"]
Instead the array seems to reset each time so I only have after the fifth emit:
["test4"]
$cast_members also has no interaction with any views so that shouldn’t affect it.
Why is it when I am emitting this event, the data in $cast_members is not retained?
Livewire version: v2.2.9
Laravel version: 8