Daniel-Pablo's avatar

livewire pagination disappear when i put another livewire component inside the loop

Hi , im facing a problem, i make a livewire pagination but this pagination fails or disappear when i put another livewire component inside the loop. Hope some can help me, thanks.

Father componen main loop:

<div>
@foreach($comments as $comment)
<p class="text-xs">{{$comment->user_comment}} </p>
@endforeach
{{ $comments->links() }}
</div>

like this work like a charm, no errors and everything is ok, but when i put and otrhe componen inside it fails, like this:

<div>
@foreach($comments as $comment)
<p class="text-xs">{{$comment->user_comment}} </p>
@livewire('pages.like-button', [ 'user_id' =>  Auth::user()->id, 'score_id' =>  $comment->id ])
@endforeach
{{ $comments->links() }}
</div>

Some one can tell me why this happened or the right way to make it work? , thank you

0 likes
4 replies
Daniel-Pablo's avatar

@webrobert thank you for the replay, but i am currently new at this kind of lenguaje can you guide me, please?

webrobert's avatar
Level 51

@Arius Tigger

<div>
	@foreach($comments as $comment)
		<div wire:key="{{ $loop->index }}">
			<p class="text-xs">{{$comment->user_comment}} </p>
			@livewire('pages.like-button', [ 'user_id' =>  Auth::user()->id, 'score_id' =>  $comment->id ], key($loop->index))
		</div>
	@endforeach
	{{ $comments->links() }}
</div>
1 like
Daniel-Pablo's avatar

@webrobert, Thank you for the documentation it help me a lot. For other that are struggling with some kind of similar bump on the way, this is the solution:

<livewire:pages.like-button  :user_id="$u_id" :score_id="$comment->id" :wire:key="$loop->index" />
1 like

Please or to participate in this conversation.