seiliaz's avatar

Livewire 3 refresh component

unfortunately, since I've updated to Livewire 3, I can't use this method for refreshing my component:

protected $listeners = ['refreshComponent' => '$refresh'];

I know that emit has been replaced with dispatch, but I have no idea how to re-render my component. in addition to this, this component is not called in another component and they are placed in a simple blade file.

0 likes
4 replies
medcharrafi's avatar

before you must listen to the event that you dispatch like #[On('post-created')] and after #[On()] ..... do a function that handles that stuff and for refreshing the component that depends on the situation that u work on I can help u if give us more info about the situation that u work with

seiliaz's avatar

@medcharrafi thanks for reaching out, well, I'm implementing an admin panel and I'm trying to use the SPA portion of livewire to creating something outstanding. but I have a bunch of problems, and the problem is that when I refresh the component it doesn't do the job as expected, for example, when I create a user, instead of updating the data of users, it ruins the data structure and shows only 1 user. I'm not sure if it's because of the front-end part (a template which I use) or it's because of livewire under the hood.

jaimevalasek's avatar

If you use $this->dispatch('refreshEdit');

class Edit extends Component {

#[On('refreshEdit')] 
public function render() 
{ 
	return view('livewire.panel.posts.edit'); 
}

public function methodResultRefreshSelf()
{
	$this->dispatch('refreshEdit');
}

}

1 like

Please or to participate in this conversation.