Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

defer feature in @this.set() livewire 3

In Livewire 2, I could postpone the update by sending the value true in the last parameter, but this possibility is not available in Livewire 3.

What is the alternative for @this.set('prop', value, true) in livewire 3 ?

like image 337
amir hosein cheraghchi Avatar asked Oct 11 '25 11:10

amir hosein cheraghchi


2 Answers

In livewire 3 you should wrap your <script></script> in @script <script></script> @endscript. This will give you access to the $wire variable to access your component.

Ref: https://livewire.laravel.com/docs/components#using-javascript

Ref: $wire object: https://livewire.laravel.com/docs/javascript#the-wire-object

Then refactor your @this.set('prop', value, true) to $wire.set('prop', value, true). Note that true is the default value for 'defer' when using set(). Setting it to false has a different effect in the end.

like image 183
Mr Seche Avatar answered Oct 14 '25 01:10

Mr Seche


Try to use livewire js events On your js file:

const isEnabled=true;
Livewire.emit('dataChanged',isEnabled);

On component php class

protected $listeners = ['dataChanged' => 'dataChanged'];
public $isEnabled;

public function dataChanged($data){
$this->isEnabled=$data;}
like image 20
Zrelli Majdi Avatar answered Oct 14 '25 01:10

Zrelli Majdi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!