In real-time applications, it can be helpful to provide a visual indication that the user's device is no longer connected to the internet.
Livewire provides the
wire:offline directive for such cases.
wire:offline to an element inside a Livewire component, it will be hidden by default and become visible when the user loses connection:
<div wire:offline> This device is currently offline.</div>
class modifier allows you to add a class to an element when the user loses their connection. The class will be removed again, once the user is back online:
Or, using the
.remove modifier, you can remove a class when a user loses their connection. In this example, the
bg-green-300 class will be removed from the
<div> while the user has lost their connection:
<div class="bg-green-300" wire:offline.class.remove="bg-green-300">
.attr modifier allows you to add an attribute to an element when the user loses their connection. In this example, the "Save" button will be disabled while the user has lost their connection: