Dispatching an event from an Action
Hi, should i dispatch an event from an action like this?
->dispatch('prova', ['prova']) doesn't work
15 Replies
Yes
@teodino93 What is the issue exactly? What's not working?
Actions aren’t livewire components. Maybe
Also in lw3 dispatch events don’t use the array syntax for data. It should be named properties.
If I write
Nothing happens, i have to do like the original post to dispatch an event... I don't know if it's an error or it's correct to do like this.
Have you tried the suggestion from awcodes? 👆
The code that i wrote on the original post works, I just wanted to be sure that should be the correct way to dispatch an event, since there is also a dispatch method.
@awcodes , Sorry for tagging you, but do you know how we can dispatch events using the
->dispatch()
method?Looking at the code it should work like you're thinking. Maybe it's a conflict in this case with the name of that action being the same as the event that is being dispatched. It might be trying to call itself.
I've tried with different names
With a null action, nothing happens on click anyway.
Might have to ask Dan.
yep, but without
->action(), ->action(null)
this doesn't workCould even be a situation where using dispatch is only meant to be used internally in action callbacks since it is probably not part of the caching that happens with actions.
hum, ok
I don't think it's an issue, but I didn't find a way to execute this. Maybe we can check with Dan on how we can use this.
Thank you for your support!
Ok so we stick to action for now, thank you for the support!
im following this thread too, on the surface it seems like action's dispatch() method doesn't work while livewire's does