Closed
Description
I'm afraid this could be a regression as I'm pretty sure it worked before 2.16. I'm following the official docs:
To work with a collection of DTOs, specify the collection type inside PHPDoc:
Here is the DTO:
<?php
namespace App\Model;
class AddressDto
{
public ?string $name = null;
}
And the simple component that use a collection of AddressDto
:
<?php
namespace App\Twig\Components;
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
use Symfony\UX\LiveComponent\Attribute\LiveAction;
use Symfony\UX\LiveComponent\Attribute\LiveProp;
use Symfony\UX\LiveComponent\DefaultActionTrait;
use App\Model\AddressDto;
#[AsLiveComponent]
class Test
{
use DefaultActionTrait;
/**
* @var AddressDto[]
*/
#[LiveProp()]
public array $results = [];
#[LiveAction]
public function update(): void
{
$address = new AddressDto();
$this->results[] = $address;
}
}
... and the Twig:
<div {{ attributes }}>
{% for result in results %}
{{ dump(result) }}
{% endfor %}
<button
data-action="live#action"
data-live-action-param="update"
>update</button>
</div>
As soon as you click the updated button (and the result array is populated) I get the following:
Unable to dehydrate value of type "array" for property "results" on component "App\Twig\Components\Test". Change this to a simpler type of an object that can be dehydrated. Or set the hydrateWith/dehydrateWith options in LiveProp or set "useSerializerForHydration: true" on the LiveProp to use the serializer.
Are you able to get this to work?
Metadata
Metadata
Assignees
Labels
No labels