Skip to content

Morphing

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.

Livewire Reference

Keyed loop items

Use Magento-typed escapers and PHP loops when keying items:

<?php foreach ($magewire->products as $product): ?>
    <div wire:key="product-<?= (int) $product['id'] ?>">
        <?= $escaper->escapeHtml($product['name']) ?>
    </div>
<?php endforeach; ?>

Morph hooks

Magewire exposes morph hooks through the magewire:init event:

document.addEventListener('magewire:init', () => {
    Magewire.hook('morph.updating', ({ el, component, toEl, skip, childrenOnly }) => {});
    Magewire.hook('morph.removed', ({ el, component }) => {});
});