I have the same problem, it seems to be a bug.
Aug 2, 2023
15
Level 1
Livewire 3: Cannot mutate reactive prop [comment] in component: [post.comments]
app/Livewire/Post/Show.php
<?php
namespace App\Livewire\Post;
use Livewire\Component;
use App\Models\Post;
class Show extends Component
{
public Post $post;
public function render()
{
return view('livewire.post.show');
}
}
resources/views/livewire/post/show.blade.php
<div class="mt-8">
@foreach($post->comments as $comment)
<livewire:post.comments wire:key="{{ $comment->id }}" :$comment />
@endforeach
</div>
<div class="mt-8">
<livewire:post.create-comment :$post />
</div>
app/Livewire/Post/Comments.php
<?php
namespace App\Livewire\Post;
use Livewire\Attributes\Reactive;
use Livewire\Component;
class Comments extends Component
{
#[Reactive]
public $comment;
public function render()
{
return view('livewire.post.comments');
}
}
resources/views/livewire/post/comments.blade.php
<div>
<div class="bg-white dark:bg-gray-700 p-4 my-4 shadow-lg rounded-lg">
<div class="text-gray-800 dark:text-white">
<strong>{{ $comment->user->name }}</strong>
<p>{{ $comment->content }}</p>
</div>
<div class="text-gray-600 dark:text-gray-400 text-sm mt-2">
{{ $comment->created_at->diffForHumans() }}
</div>
</div>
</div>
Please or to participate in this conversation.