How to make data in Livewire component reactive?
Hi,
I have a Livewire component inside my form where I'm passing values for
width
and height
like this:
In the component class I define the variables like this:
and then I can use {{ $width }}
in the blade view. However, the data does not seem to be reactive this way. If I change the values in the form fields, they are not getting updated in the Livewire component. Both text fields in the form are ->live()
of course. What can I do to make the values reactive?Solution:Jump to solution
```php
Section::make('Details')
->columnSpan(3)
->dehydrated(false)
->live()...
8 Replies
I think this is similare to how the ViewField works. I had to put them schema in a closure that then wrapped around which allows it to be re-run
Could you give an example? I didn't use the
ViewField
because I thought you can't use closures for dynamic data inside of ->viewData()
.Solution
I use the above, as the section has a schema and wrapped in a function, we can pass the data in that way
Can you simply use
{{ $record }}
in your view without any further configuration this way?I believe so
But I don't think the record updates with the form values until saved.
Thanks, it works this way! I decided to wrap it in a
Group
since I don't need a Section
there. This has to be a hack though right?which is why $get is usually used
Yep absolutely