I am having a serious problem with Livewire in passing data from an api response to the component blade file. At first it loads fine, the moment i click. the dropdown it throws an error below.
Livewire encountered corrupt data when trying to hydrate the [sign-up] component. Ensure that the [name, id, data] of the Livewire component wasn't tampered with between requests.
I have a dropdown that i am loading professions, it loads fine at first but the moment i select something fro the dropdown, it throws that error.
Below is my component code
<?php
namespace App\Http\Livewire;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;
use Guzzle\Http\Exception\ClientErrorResponseException;
use Livewire\Component;
class SignUp extends Component
{
public $response = 0;
public $data;
//get all professions and their related prefixes
public $professions;
public $profession_id;
public $prefix;
public function mount()
{
$response = Http::get('http://localhost:8000/api/sign_up');
$collection = json_decode($response);
$this->professions = collect($collection->professions);
}
public function hydrate()
{
$response = Http::get('http://localhost:8000/api/sign_up');
$collection = json_decode($response);
$this->professions = collect($collection->professions);
}
public function render()
{
return view('livewire.sign-up', [
'professions' => $this->professions
]);
}
}
Below is my component blade dropdown
<div class="form-group">
<select wire:model="profession_id" name="profession_id" class="form-control form-control-lg"
id="exampleFormControlSelect2">
<option value="">Choose Profession</option>
@foreach($professions as $profession)
<option value="{{$profession->id}}">{{$profession->description}}</option>
@endforeach
</select>
</div>
mountandhydratelike that.helloorhello\nyou will likely get a corrupted data because the hash will not be the same.