Skip to content
Advertisement

Laravel Livewire Javascript data is not refreshed after component is re-rendered

I need support because my javascript data is not updating when the livewire component gets re-rendered.

I use Fullcalendar in a livewire component

JavaScript

In my class I have $this->dispatchBrowserEvent('contentChanged'); in the render method.

When I update $events I see the updated data in the dump [1] but events [2] is not updated.

The log [3] shows always the same events

Advertisement

Answer

Since you’ve pushed the script out of your component (which is a good idea), it will not be touched when Livewire is re-rendering and doing its DOM-diffing.

So instead, you can pass the event-data as a parameter which you can accept in the event-listener.

So, add the data with the event,

JavaScript

And accept it in the listener, by passing e into the callback (which is the event-object), and access the data in e.detail.

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement