Get your next remote job on LaraJobs.

Prevent a Livewire component from re-rendering

Prevent a Livewire component from re-rendering

Introduction to re-rendering prevention in Livewire

I previously talked about various way to re-render a Livewire component. But now, let’s do a 180° and talk about doing the opposite: preventing re-renders!

Block re-renders in a Livewire component

Sometimes, you might want to run an action or listen to an event in a Livewire component. Problem is: this triggers a re-render. The solution? The new Livewire\Attributes\Renderless attribute!

namespace App\Livewire;
 
use Livewire\Component;
use Livewire\Attributes\Renderless;
 
class Show extends Component
{
#[Renderless]
public function incrementViewCount()
{
$this->model->incrementViewCount();
}
}

This can be a huge win for the performances of your Laravel application.

Oh and by the way, if you still can’t deal with PHP’s new attributes, you can use the skipRender() method like so:

namespace App\Livewire;
 
use Livewire\Component;
 
class Show extends Component
{
public function incrementViewCount()
{
$this->model->incrementViewCount();
 
$this→skipRender();
}
}

Be the first to comment!

Get help or share something of value with other readers!

Great deals for enterprise developers
The latest community links

Recommended articles

How to force re-render a Livewire v3 component

Stop pulling your hair. Here's a solution to your reactivity issues in Livewire.

Fix the /livewire/livewire.js 404 not found error

Learn how to fix the 404 not found error occurring for /livewire/livewire.js.

Discover how to craft an ever-present chat widget with Livewire v3's persistence features in Laravel - step-by-step guide included.

Laravel Volt: simplify how you write Livewire components

Laravel Volt is a great new addition to Laravel's extensive ecosystem that brings single-file components à la Vue.js to Livewire. Let me help you get started.

Create a SPA in seconds using wire:navigate in Livewire v3

Discover how to boost the speed of your Laravel apps, mimicking an SPA, without building an API, using Livewire v3 and the new wire:navigate attribute.

20+ Laravel best practices, tips and tricks to use in 2024

Learning a framework can be overwhelming, but time and execution will make you a master. Here are some best practices to help you toward your goal.

Laravel interview questions and answers for 2024

Nailing a Laravel job interview can be a daunting task, but with the right preparation and mindset, you can set yourself up for success.

7 Laravel RESTful APIs best practices for 2024

Master the art of crafting RESTful APIs with Laravel thanks to these best practices.

- / -