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

wghughes95's avatar

Listener for refresh component is triggered but $refresh is doing nothing

I have two child components nested within a Bank Details page. One to edit and one is to create. When I create a record I need the page to navigate to the respective edit tab, where the new record should be displayed as the data will always pull the most recently updated. To achieve this I am trying to fire an event from the create component $this->dispatch('bank-account-created');, which is then listened for in the edit component.

    #[On('bank-account-created')]
    public function newAccount()
    {
        $this->dispatch('refreshComponent');
    }

As far as I can tell, the event is fired and is listened to, however the helper function $refresh simply isn't working and I have no idea what it is that I'm doing wrong.

bank-details.blade.php

bank-details-create.blade.php

<div>
    <div class="flex flex-row mt-5" x-init="$wire.on('change-active-tab', (e) => activeTab = e[0])">
        <form wire:submit="save" class="w-full">
            <div class="bg-white border px-8">
                <div class="w-full my-8">
                    <div class="mt-4 grid grid-cols-1 lg:grid-cols-2 gap-4 items-end">
                        <label>
                            <span class="block">Select Bank Account Type<span class="align-super text-red-600">*</span></span>
                            <x-input.select-input wire:model.change="account_type"
                                                  class="mt-2 p-2 w-full"
                                                  :options="$this->account_types"
                            />
                            <x-input.input-error :messages="$errors->first('account_type')" class="mt-2"/>
                        </label>                       
                </div>

            </div>

            <div>
                <button type="submit"
                        class="mt-2 p-2 bg-cp-accent-dark-blue text-white text-sm rounded-md float-right">
                    Add Account
                </button>
            </div>
        </form>
    </div>
</div>

BankDetailsCreate.php

BankDetailsEdit.php

BankDetails.php

<?php

namespace App\Livewire\Investor\Pages;

use App\User;

class BankDetails extends Component
{
    public User $user;

    public function mount()
    {
        $this->user = auth()->user();
    }

    public function render()
    {
        return view('investor.pages.bank-details');
    }

}
0 likes
2 replies
valentin_vranic's avatar

@wghughes95 or there's another approach refreshing a component if it's needed, listening to an event directly on component declaration. Straightforward, reduces code noise, simple

<livewire:investor.components.bank-details-edit @refreshComponent="$refresh" />

Please or to participate in this conversation.