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

MahmoudAdelAli's avatar

Cannot mutate reactive prop

I have a beginner issue here , i have a component that contain freelancers

class Freelancers extends Component
{
    use WithPagination;
    protected $paginationTheme = 'bootstrap';
    #[Validate('required|string|min:1')]
    public $term = '';
   #[Reactive]
    public $results = [];

 public function render(): View
    {
        return view('livewire.client.init.freelancers', [
            'freelancers' => $this->getFreelancers(),
        ]);
    }

// Function To Get Freelancers
// updatedTerm($value) to Search

so in first i created nested component for result and also another for search and all i got static result without any reactive result , so i decided to use #[Reactive] like anyone and i got

Cannot mutate reactive prop [result] ...

collapsed all components in one component and still got it , until i removed it and it works with the search but it's not accepted to put all search and filters in one component , i know there's an event listeners and also i can't pass data from child to parent , but here all i want to do to make a component for results inside the index that contain the search box , it works with me all the times , but here like it encountered me , even after i put everything in one single component , so it not working with nested or at one component .

0 likes
4 replies
LaryAI's avatar
Level 58

The error message "Cannot mutate reactive prop [result]" suggests that you're trying to directly modify a reactive property in a way that is not allowed. In Livewire, you should avoid directly mutating properties that are marked as reactive. Instead, you should use methods or events to update these properties.

Here's a solution to your problem:

  1. Remove the #[Reactive] attribute: Since you're encountering issues with the #[Reactive] attribute, you can manage reactivity using Livewire's built-in features like events and methods.

  2. Use Livewire Events: If you want to update the results property based on some action (like a search), you can use Livewire events to handle this.

  3. Update the results property using a method: Instead of trying to directly mutate the results property, create a method that updates it.

Here's an example of how you can structure your component:

Explanation:

  • updatedTerm Method: This method is automatically called whenever the term property is updated. It calls the searchFreelancers method to update the results.

  • searchFreelancers Method: This method updates the results property by fetching freelancers based on the search term.

  • getFreelancersByTerm Method: This is a placeholder for your logic to fetch freelancers based on the search term. You can replace it with your actual query logic.

By using methods to update your properties, you can avoid directly mutating reactive properties and adhere to Livewire's best practices.

1 like
critic's avatar

Make own Reactive Attribute class and override dehydrate method

namespace App\Livewire;

#[\Attribute] class Reactive extends \Livewire\Attributes\Reactive { // public function dehydrate($context) { //die('sees');

    $context->pushMemo('props', $this->getName());
}

}

ehask71's avatar

Did you ever fix your issue? I am dealing with a similar thing ..... I have an hours field and I wanted it to recalculate a total based on the hours number in the input. I only see updatedHours() triggered on submit ... Tried #[Reactive] attribute and got the mutate ....

Laravel 11 on Herd I dont see any network calls

critic's avatar

Make own Reactive Attribute class and override dehydrate method

<?php

namespace App\Livewire;

#[\Attribute]
class Reactive extends \Livewire\Attributes\Reactive
{
    //
    public function dehydrate($context)
    {
        $context->pushMemo('props', $this->getName());
    }
}

Please or to participate in this conversation.