livewire / volt

Volt is an elegantly crafted functional API for Livewire.

Home Page:https://livewire.laravel.com/docs/volt

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

States, Multiples Declarations

devajmeireles opened this issue · comments

commented

Volt Version

v1.0.0@beta2

Laravel Version

latest

PHP Version

8.1.21

Database Driver & Version

SQLite

Description

I don't know if this is really a bug or expected behavior, anyway I'm reporting this in order to help.

  1. State with closure and non-closure:
<?php

use function Livewire\Volt\state;

state(['title' => fn () => $title], '');

👇

CleanShot 2023-08-01 at 1 08 15

  1. State with closure and variable with no value:
<?php

use function Livewire\Volt\state;

state(['title' => fn () => $title, 'description']);

👇

CleanShot 2023-08-01 at 1 09 29

Steps To Reproduce

Try to do the same thing as reported above.

Both examples declare state incorrectly. Here are the ways you can declare state:

state('counter');
state(['counter']);
state(['counter' => 0]);
state(counter: 0);
state(['counter' => fn () => User::count()]);
state(counter: fn () => User::count());