Source: ryangjchandler.co.uk

How to Watch Alpine Stores for Changes
With Alpine 2.x and Spruce, you could define a global store and also a watcher for a particular store property: Anytime the counter.count property was updated, the callback would be called. With the introduction of Alpine.store in Alpine 3.x there is no longer a dedicated watch method for stores, but we can still get the same effect with Alpine.effect (no pun intended): This works because Alpine will keep track of any dependencies / reactive properties we use inside of the callback and invoke it when any of them change. Keep in mind that Alpine will run this callback function atleast once, so make sure you check for your initial state and prevent anything from happening.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners