Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

MerryChristmas's avatar

Livewire - problem updating JS variable

My LiveWire component is checking if task was completed => when it is completed it will insert variable into a page.

<script>
var taskResult = [ ... ];
</script>
  1. Task is completed before I load page => variable is inserted on the first load => variable is accessible by JS.

  2. Task not completed on initial load => Livewire refreshes component a few times => task is now completed => inserts variable into HTML => this variable is NOT accessible by JS function although I see that variable is inserted into HTML code.

0 likes
1 reply
vincent15000's avatar

That's normal because once JS is loaded, the variables are not updated.

But you are using Livewire. Why don't you handle this variable with Livewire instead of JS ?

You can also use AlpineJS, it works fine with Livewire (Livewire uses it).

Please or to participate in this conversation.