Is it possible to update a property (model) without refreshing the component?
Update property without refreshing component
Hey, @Alexandru
Yes, This is the point of livewire you can the following:
public function save()
{
Model::create($data);
$model->refresh();
}
I’m talking about Livewire component, I want to update a public property without refreshing (rerendering) Liviewire
maybe if you be more clear about what you are trying to do! are you updating a property typing in input and don’t want request while do it?
Let’s say we have public $valueA;
From the FE I want to update it’s value but without rerendering the FE, I only need it’s new value the next time it rerenders.
The value is not used as model in the FE, just if ($valueA == ‘whatever’)
I update the value via a an action method wire:onclick=“updateValueA()”
Hi,
I believe for what you’re seeking there’s the defer keyword
(but, alas, I couldn’t make it work…)
Livewire makes it very easy to update properties without refreshing.
Say in your livewire blade files you have a value that shows the time: to make the time update without you refreshing:
<div>
<div wire:poll.750ms>
Current time: {{ now() }}
</div>
</div>
The wire:poll will continuously update the div element without you refreshing.
using just wire:poll will update it every 2 seconds.
To set the time yourself do wire:poll.100ms etc ms here means milliseconds.
that’s not what I asked
Hi, you have two options
1 using wire:model.defer// this only update when there is a network update(any action that requires a roundtrip for update)
2. Updating the property using JavaScript when a specific action happens, updating the value directly or emitting an event.
For good user experience, when there are a lot interaction in a form , I use the second option, most of the time combine with AlpineJs.
Hope that help