You can hook into the
updated() method of your component lifecycle to have your code execute on update. And not on first render:
It might be a bit more difficult as you’re wanting to execute JS on refresh. You may want to use
$this->dispatchBrowserEvent('js-event') to trigger your JS code. I tried to find the docs on this method but I don’t think it’s in the docs yet. Basically, it will call the
I’m just typing out the following from my head and if I have some time a little later, I’ll test to make sure it works but to get you started:
public function updated()
<div x-data="appData()" x-on:js-event.window="jsMethod()">
<!-- HTML -->
// your code
This is Alpine but you can use whatever JS you’re comfortable with.
x-on is listening for
window and will trigger
jsMethod() when the event is raised.
Your child component shouldn’t kick up anything that will trigger a refresh on the parent component.