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

Triumfator's avatar

How bad is it to use wire:poll to refresh a variable?

How bad is it to use wire:poll with 2 second delay to refresh a variable within Livewire view?

Basically, i have a livewire shopping cart page that gets dynamically calculated shipping values (returned as an array) from cart service controller. User is able to toggle between ground and shipping rate in livewire rendered view. If user changes their country, shipping rates get recalculated, but they don't always get refreshed in rendered view.

The only thing I was able to use to fix this issue and to refresh things perfectly every time is by using wire:poll in livewire view around the variable that had problems updating.

How bad or ghetto is this method?

0 likes
5 replies
CorvS's avatar

@triumfator Using polling in the first place is not necessarily bad, but in your case it seems not like the best option. Did you create a nested component for your shipping rate?

1 like
Triumfator's avatar

I'm currently using darryldecode/cart shopping cart as a service and livewire cart page pulls data out of it and that's why i had to implement wire:poll as a band aid solution. I will scrap that package when i rewrite a shopping cart completely in livewire.

chaudigv's avatar

You need to use Event Listeners approach rather than polling.

    protected $listeners = ['updateCart'];

    public function updateCart()
    {
        // do your thing
    }

Now, everytime there's a change like ground and shipping rate, changes their country or anything related to cart, then you need to trigger an event like this $this->emit('updateCart');

Snapey's avatar

@chaudigv read the OP's other question and you will see that this is not the issue.

Its probably purely a dom-diffing problem.

Please or to participate in this conversation.