The first time will be executed as intended, but the second and subsequent ones will execute a different element from the target.
I hope you can see the details in the image below.
Do you have a solution in Livewire?
Blade
<div> <h2>User List</h2> <ul> @foreach($users as $user) <div> <div wire:loading.remove wire:target="deleteUser({{ $user->id }})"> <li> {{ $user->name }}<button wire:click="deleteUser({{ $user->id }})">delete</button></li> </div> <div wire:loading wire:target="deleteUser({{ $user->id }})"> Removing... </div> </div> @endforeach </ul> </div>
Component
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use App\User;
class UserList extends Component { public $users; public function mount() { $this->users = User::all(); } public function deleteUser($id) { try { $this->users = $this->users->filter(fn (User $user) => $user->id !== $id); User::findOrFail($id)->delete(); } catch (\Throwable $th) { //throw $th; } } public function render() { return view('livewire.counter'); } }