You're browsing the documentation for an old version of Livewire. Consider upgrading your project to Livewire 2.x.

Defer Loading

Livewire offers a wire:init directive to run an action as soon as the component is rendered. This can be helpful in cases where you don't want to hold up the entire page load, but want to load some data immediately after the page load.

use Livewire\Component;

class ShowPost extends Component
    public $readyToLoad = false;

    public function loadPosts()
        $this->readyToLoad = true;

    public function render()
        return view('', [
            'posts' => $this->readyToLoad
                ? Post::all()
                : [],
<div wire:init="loadPosts">
        @foreach ($posts as $post)
            <li>{{ $post->title }}</li>

The loadPosts action will be run imediately after the Livewire component renders on the page.

← Previous Topic

Dirty States

Next Topic →