Level 51
Why are you dispatching an event from javascript?
I am trying to get dispatch from 1 component to another. At the moment I getting this error "Attempt to read property "name" on null"
Here is the blade file that is dispatching
@if(!empty($query))
@if(!empty($contacts))
@foreach($contacts as $contact)
<option><a wire:click="showphotos({{$contact->name}})" href="/create-photo/{{$contact->id}}">{{$contact->name}}</option>
@endforeach
@else
<div>No Result</div>
@endif
@endif
$wire.dispatch('create-photo',{$contact->name});
Here is the listening component
class CreatePhoto extends Component { public $contact;
#[On('create-photo')]
public function showphotos($name){
$this->name =$name;
}
public function render()
{
return view('livewire.create-photo');
}
}
Here is the blade file
<h4>{{$contact->name}}</h4>
Please or to participate in this conversation.