livewire / volt

Volt is an elegantly crafted functional API for Livewire.

Home Page:https://livewire.laravel.com/docs/volt

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Functional API Doesn't Support Interaction to Livewire `$refresh` Magic Action

devajmeireles opened this issue · comments

commented

Volt Version

1.6.3

Laravel Version

11.4.0

PHP Version

8.3.6

Database Driver & Version

N/A

Description

While Livewire offers two ways to perform $refresh operation:

In an original Livewire component

Using #[On] on top of the class, implemented here: livewire/livewire#7667

#[On('refresh::create-post')]
class CreatePost extends Component
{
    // ...
}

Using the old approach $listeners:

class CreatePost extends Component
{
    protected $listeners = [
        'refresh::create-post' => '$refresh',
    ];
}

In Volt's functional API style, we have no way of doing this. The docs doesn't mention anything about this. Thinking it would possibly be ready to use, but out of the docs, I tried:

on(['refresh::create-post' => fn () => '$refresh']);

on(['refresh::create-post' => '$refresh']);

None of this worked.

Steps To Reproduce

  1. Create a Volt component using the Functional API
  2. Try to dispatch an event that requires the Livewire $refresh magic action

Thanks. We'd appreciate a PR to help make this possible.

commented

Thanks. We'd appreciate a PR to help make this possible.

Sure thing! I can try that, but don't you think it's better to keep the issue open with the help wanted label?