myregistration's avatar

Livewire v3 Syntax

Can we still use @livewire() as opposed to <livewire /> for including components? I don't see any reference to it in the v3 documentation. Does that mean we shouldn't? If it's still acceptable, should we pass the key as a named parameter, such as key: 'somevalue'?

0 likes
5 replies
LaryAI's avatar
Level 58
In Livewire v3, the preferred method for including Livewire components in your Blade views is by using the <livewire:component-name /> tag syntax. This is a more Blade-native approach and aligns with the component tag syntax introduced in Laravel 7.

However, if you need to use the older `@livewire` directive for some reason, it should still work as it is not removed, but it's not documented because it's not the recommended approach in Livewire v3. The Livewire team encourages developers to use the new syntax for better readability and consistency with Laravel's Blade component syntax.

If you choose to use the `@livewire` directive, you can pass parameters including the key like this:

```blade
@livewire('component-name', ['param1' => $value1], key($someUniqueValue))

Or, if you want to use named parameters, you can pass them as an associative array:

@livewire('component-name', ['param1' => $value1, 'key' => $someUniqueValue])

Remember that using the @livewire directive is not the recommended way in Livewire v3, and you should prefer the new <livewire:component-name /> syntax whenever possible. This new syntax also supports passing parameters, including a key:

<livewire:component-name :param1="$value1" :key="$someUniqueValue" />

This is the cleaner and more modern approach that aligns with the direction the Livewire and Laravel communities are moving towards.

myregistration's avatar

@LaryAI I believe you are supposed to use :wire:key, not :key

<livewire:component-name :param1="$value1" :wire:key="$someUniqueValue" />

Snapey's avatar

not sure I can add anything

Why the friction to using <livewire .... its only a label?i

Please or to participate in this conversation.