You're browsing the documentation for an old version of Livewire. Consider upgrading your project to Livewire 3.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.

            
1use Livewire\Component;
2 
3class ShowPost extends Component
4{
5 public $readyToLoad = false;
6 
7 public function loadPosts()
8 {
9 $this->readyToLoad = true;
10 }
11 
12 public function render()
13 {
14 return view('livewire.show-posts', [
15 'posts' => $this->readyToLoad
16 ? Post::all()
17 : [],
18 ]);
19 }
20}
            
1<div wire:init="loadPosts">
2 <ul>
3 @foreach ($posts as $post)
4 <li>{{ $post->title }}</li>
5 @endforeach
6 </ul>
7</div>

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

← Previous Topic Dirty States
Next Topic → AlpineJS