Custom JS not executing on rerenders with Livewire
I am trying to make Photoswipe JS work on images that are loaded in Laravel Livewire. The JS file is include in app.blade.php
@vite(['resources/js/lightbox.js'])
The JS executes well when I first load and click the image, a lightbox appears. But once I go to other pages and come back, it no longer works and I have to refresh. I wonder what am I missing.. I have tried clearing cache and views and also saw the wire:key=rand() method in the div which have failed.. I also read about emit method but not sure how to do it in the custom js.
The lightbox.js has this code (from documentation of Photoswipe)