Hi
i have 2 components parent and child.
When i update something, the lists not refreshed.
I assume it's the 'key' behaviour
in parent:
@foreach ($users as $user)
<livewire:user.show :user="$user" :key="$user->id">
@endforeach
Assume, user table have two columns: username and email
when i update something from the child, it calls refresh button on my parent component
protected $listeners = [
'userUpdated' => '$refresh'
];
public function render()
{
$this->users = User::orderBy('id', 'desc')->get();
return view('livewire.user.index');
}
Problem:
the lists not changing when i update it, i need to refresh first, then see the changes.
I tried adding 'username' as more unique key
<livewire:user.show :user="$user" :key="$user->id. $user->username">
it did changes, when i update the username.
but when i update the email, its not updating the list.
Other fact: if i change the key to uniqid it also works, but not sure if it is a best practice
Not sure, what should i give the key in livewire to make it automatically adapat with any changes.