Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sarukomine's avatar

`updated` lifecycle hook dont work with livewire/volt

<?php 
use function Livewire\Volt\{state, updated};

state(['count' => session('count', 0)]);

updated(['count' => fn () => session()->put('count', $this->count)]);

$addOne = fn () => $this->count++;
$minusOne = fn () => $this->count--;
$resetCounter = fn () => $this->count = 0;
?>

<div>
    <h1>{{ $count }}</h1>
    <button wire:click="addOne">+1</button>
    <button wire:click="minusOne">-1</button>
    <button wire:click="resetCounter">Reset</button>
</div>

I want to use updated function to watch count for store count value in session, but this function not working for me. Anyone have idea about this? Or I doing wrong way?

0 likes
4 replies
vincent15000's avatar
public function updatedCount($value)
{
	// save the value in the session
}
sarukomine's avatar

@vincent15000 Sorry I didn't make it clear. The code is written in blade file with livewire/volt package, and does not use Class.

1 like

Please or to participate in this conversation.