Events
Laravel Livewire Documentation Reference
Since Magewire is heavily inspired by Laravel Livewire, many concepts are either identical or very similar. To avoid duplicating documentation, this page only covers Magewire-specific and platform-specific details. For all general concepts and in-depth explanations, you can refer to the corresponding Laravel Livewire documentation.
Component events use Livewire 3's dispatch() and #[On] concepts. Use them for application communication between components and browser code.
use Magewirephp\Magewire\Attributes\On;
$this->dispatch('cart-updated', count: $this->itemCount);
#[On('cart-updated')]
public function refreshSummary(int $count): void
{
// …
}
The V1 emit*() methods and $listeners property are migration APIs provided by the backwards-compatibility layer. New Magewire 3 components should use dispatch() and attributes.
Framework hooks are different
Magewire also has an internal on() / trigger() pipeline used by mechanisms and features. Those hooks are framework extension points, not component-dispatched events.
use function Magewirephp\Magewire\on;
on('render', function ($component, $view, $data) {
// Before render.
return function ($html) {
// After render.
return $html;
};
});
The current observable internal map includes:
- Magewire lifecycle:
magewire:component:construct,magewire:component:reconstruct,magewire:component:build,magewire:view:compile,magewire:setup, andmagewire:boot; - component lifecycle:
pre-mount,mount.stub,mount,hydrate,update,call,render,render.placeholder,dehydrate, anddestroy; - Magento rendering:
magento:block:render,magento:block:rendered, andmagento:template:render; - transport and integrity:
request,response,checksum.generate,checksum.verify,checksum.fail, andsnapshot-verified; - utility hooks:
__get,__unset,__call,exception,flush-state, andprofile.
Not every internal event has the same arguments or return pipeline. Inspect the tagged call site before writing a low-level hook.
Magento observers
The observer bridge re-emits its explicit internal event map as Magento events. Non-alphanumeric characters become underscores:
magewire:component:construct → magewire_on_magewire_component_construct
checksum.fail → magewire_on_checksum_fail
render → magewire_on_render
See Magento Observer Events for registration and before/after callback semantics.