What are the public, private and protected properties in your component ?
Private and Protected properties in Livewire
Hi Guys,
Please let me know if I understand it and I am using it correctly.
I use private / protected properties for livewire components when these props do not need to be fetched / rehydrated on every re-render of the component. This leads to significant perfomance boost because these queries are only fetched once in the mount() method where they are in best case put into Cache. Why in mount? Because some other methods in mount might depend on the data.
Then when I am passing the properties in render method to view like this:
public function render()
{
$this->getOtherColors();
return view('livewire.' . eshop()->getViewPath() . '.colored-product.colored-product-panel', ['otherColors' => $this->otherColors]);
}
I still need to call the $this->getOtherColors() method - which is just and Cache::remember and simple query for model all let's say - it does not matter.
My questions are: Is that correct? How to avoid the need to call it on each render? Is the solution to make custom hydrateOtherColors method and make it public - in this method just fetch it from cache?
Please or to participate in this conversation.