I have a livewire component which has a public property $categories
and i fetch this data within the mount method.
However, i have noticed (through laravel debugbar package) that this property gets hydrated every time a change is made to the component. This is making my component very slow. I have like 3000+ categories including subcategories. The categories do not change very frequently.
I am using livewire 2.3
// livewire component
public $categories;
public $amounts = [];
public function mount() {
$this->categories = Category::with('subcategories')->get();
}
here is the blade code
// blade
@foreach ($categories as $category)
{{$category->name}}
<input type="text" wire:model="amounts.{{$loop->index}}"/>
@foreach ($category->subcategory as $subcategory)
{{$subcategory->name}}
<input type="text" wire:model="amounts.{{$loop->index}}"/>
@endforeach
@endforeach
So, each time I enter a value in one of the amounts fields, the $categories
property gets hydrated and query data from db.
My question is, is there any way I can prevent this property from getting hydrated. as the categories does not change from a change in the component, I feel like it is useless to query again from db.
Thanks in advance