Mount data empty while calling function in component

Hi all,

  • In component, mount function I set user data, and in view file data is populated successfully. Now in view once I click on the button(which is calling one component method) then user data gets empty

Live wire component:

class UserBlogs extends Component
{
    public $user;

    public function mount(){
        $this->user=User::select('name','address_address')
        ->leftJoin('addresses', 'users.id', '=', 'addresses.address_user_id')
        ->first();
    }

    public function render()
    {
        return view('livewire.user-blogs');
    }

    public function userClick(){
    }
}

Blade file :

<div>
    <button type="button" class="button" wire:click="userClick">wire click event</button>
    <table class="m-3">
        <thead>
            <tr>
                <th>
                    Name
                </th>
                <th>
                    Address
                </th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>
                    {{$user->name}}
                </td>
                <td>
                    {{$user->address_address}}
                </td>
            </tr>
        </tbody>
    </table>
</div>

Hi!
I think you should pass in the plade file the user parameter for the click function.
In the controller you should add userClick($user)
I hope it helps.

HI @faxunil,

Thanks for reply. Is there any other way?
If i have many methods and parameters in that case that not ok to bind every parameter in method.