Closed vidneu closed 2 months ago
Right. So the Livewire state does not get directly updated with the Vue/React state nor vice-versa. They're independent.
You can make them update by $wire.set() and $wire.watch, or other event bus you might want to put in place.
Maybe there's space to evolve for something like that, in the future.
The best approach, 100% reliable is to think of this as a "separate" world, but that communicates easily.
Ok, so this is pseudo-code, just coded here, it might fail something, but I hope you get the idea.
I will have demos set in place, and make this more clear.
And of course, let me know if it worked for you!
(...)
// Set initial value
const amount = ref(mingleData.amount)
const doubleTheAmount = () => {
wire.doubleIt(amount.value)
.then(data => amount.value = data)
}
(...)
<button class="btn" type="button" @click="doubleTheAmount">Double it</button>
(...)
(...)
public function doubleIt($amount)
{
// you return a value so that JS will have it
return $amount * 2;
}
(...)
Yup, that worked for me. Thanks a lot!
I am not sure if this is a bug or if I am missing something here. I am thankful for every advice.
I have expanded the example from the documentation with an $amount var in the Livewire component. I want to reactively display it in my Vue Component. Via console.log I have confirmed, that the wire.amount value updates in JS. But the displayed value does not seem to update.