Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

yoman's avatar
Level 2

livewire update not working even with key

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.

0 likes
6 replies
Snapey's avatar

Your problem is with the listener, not the key

Are you expecting the list to change? why does the child not send its new content to the view?

Why are you casting the whole user list into a public property?

Sorry but this is also not a good case for a child component. What dpes your child do exactly?

yoman's avatar
Level 2

hey Snapey thanks for replying..

Its an update method via modal that i make. I separate the modal in to other component, to update one of the user

refresh will take care of that as far as i know. "render" method always called everytime emit happened as long as the listener is there. So render method will get the new data from DB, without passing any content from emit/listener

Let's just say it's a bad way, i still want to know why it doesn't work, while using something like uniqid() as key is working.

chaudigv's avatar

@yoman I came across exact issue multiple times... I simply append time() to the key.

  <livewire:user.show :user="$user" :key="$user->id . time()">
1 like
yoman's avatar
Level 2

yes, that's my current solution, I add the link to the issue on github

Please or to participate in this conversation.