widget doesn't update properly from another property received with $listeners

Hello friends!! I have two components: WidgetA where I set a filter
public string $filter = 'weekly';
public string $filter = 'weekly';
and I use setFilter to fire an event filterUpdated
public function setFilter(string $filter): void
{
$this->filter = $filter;
$this->dispatch('filterUpdated', $this->filter); // Emitir el evento con el nuevo filtro
}
public function setFilter(string $filter): void
{
$this->filter = $filter;
$this->dispatch('filterUpdated', $this->filter); // Emitir el evento con el nuevo filtro
}
Then, in the WidgetB I have this
public string $filter = 'weekly';
protected $listeners = ['filterUpdated' => 'setFilter'];

public function setFilter(string $filter): void
{
$this->filter = $filter;

}

public function table(Table $table): Table
{
....
}
public string $filter = 'weekly';
protected $listeners = ['filterUpdated' => 'setFilter'];

public function setFilter(string $filter): void
{
$this->filter = $filter;

}

public function table(Table $table): Table
{
....
}
When filter is updated in WidgetA I get the value but looks like widget renders before getting the new value for filter, because when I update again the render take the previous value.
Could you help with any ideas? Thanks,
1 Reply
ingeday
ingeday3w ago
In different places I found that I had to add the updated method but this method didn't run so I made a reset of the table in the setFilter method.
public function setFilter(string $filter): void
{
$this->filter = $filter;
$this->resetTable();
}
public function setFilter(string $filter): void
{
$this->filter = $filter;
$this->resetTable();
}
Thanks,
Want results from more Discord servers?
Add your server