Problem description:
In my RecipeList.php I am showing the list of recipes:
@forelse($recipes as $recipe)
<x-recipe-card :recipe="$recipe"/>
@empty
<p>error</p>
@endforelse
Inside <x-recipe-card :recipe="$recipe"/> I have another livewire component:
<livewire:like-dislike :recipe="$recipe"/>
Upon the initial page load, the like buttons are displayed correctly on all cards. However, as soon as I change the sorting ($sort) within the same parent component, RecipeList, the buttons only remain on the first recipe, while they disappear from all subsequent ones.
Sequence Of Steps:
- Load recipe list page (pagination, default sorting "popularity").
- Like/Dislike buttons are visible on each recipe card.
- Select "newest" or "oldest" in the dropdown sorting list.
- Problem: The first recipe still has buttons, but the rest have disappeared.
What i tried:
I added wire:key, but it didn't help, on the contrary, it even caused an error in the logic of alpine.js inside x-recipe-card
@forelse($recipes as $recipe)
<div wire:key="{{ $recipe->id }}">
<x-recipe-card :recipe="$recipe"/>
</div>
@empty
<p>error</p>
@endforelse
Conclusion:
How can i make the parent component RecipeList.php be able to track the child LikeDislike.php provided that it is in the blade component
@livewire('like-dislike', ['recipe' => $recipe], key($recipe->id))? I believe it's something to do with how livewire handles re-rendering.