Skip to content

Anatomy of a component

Magewire components are PHP classes inheriting from \Magewirephp\Magewire\Component.

By convention, Magewire component classes reside inside a Magento module within a Magewire/ directory.

Magewire component classes can implement hook methods. If such a method exist on a component, it will be called at the appropriate time.

Two of the most used hook methods are mount(), which is called once when the page is initially rendered, and booted(), which is called on the initial preceding page request and all subsequent requests.

More information about available lifecycle hook methods can be found in the component Lifecycle hook methods page.

Magewire is aware of all public properties and methods on magewire a view model.

Reserved Property Names

There are a couple of reserved properties that are declared by the abstract view model and can not be used for custom code, like $id and $name.

Because these are common property names, it is easy to declare a conflicting property with the same name in a child class. Doing so breaks Magewire.
Choose alternative property names instead, for example $entityId and $productName instead of $id or $name.

Some of theses properties are public, some are protected - in either case, do not use them for custom purposes in your own Magewire components!
Some may be used as internal implementation details, some are intended to be used by custom components for specific purposes.

At the time of writing, the following properties are used by Magewire:

  • public $id
  • public $name
  • protected $dispatchQueue
  • protected $renderedChildren
  • protected $request
  • protected $response
  • protected $eventQueue
  • protected $errors
  • protected $listeners
  • protected $flashMessage
  • protected $uncallables
  • protected $queryString
  • protected $redirect
  • protected $skipRender
  • protected $loader
  • protected $validator
  • protected $rules
  • protected $messages