I have an alert component that I hide using AlpineJS but I want it to be visible again after Livewire re-renders.
Showing the alert using Livewire component
@if(Session::has('success'))
<x-success-alert :message="Session::get('success')" />
@endif
AlpineJS component
<div x-data="{show: true}">
<div x-show="show">
<span>{{ $message }}</span>
<button @click="show = false">×</button>
</div>
</div>
The solution is to force Livewire to add that element in the dom again by adding wire:key
to a random value.
<div wire:key="{{ rand() }}">
<div x-data="{show: true}">
<div x-show="show">
<span>{{ $message }}</span>
<button @click="show = false">×</button>
</div>
</div>
</div>
With that way, Livewire will destroy the old dom element and add the new one which re-init the Alpine component.