[solved] Wire:click not updating variable on page

What seems to be the problem: I’m trying to simply have a button change a text in a

. The component is launched as the dd() shows the result of the new value, but doesn’t update on the page.
I’m just a beginner, but I’ve created other pages where I open a modal with a button similar to this (I set $isOpen = true). I must miss something, but I can’t find it.
If someone has an idea where I can look for?
Thanks

Steps to Reproduce: see code examples.

Are you using the latest version of Livewire: Livewire 2.x, Laravel 8, JetStream, Tailwind css,

Do you have any screenshots or code examples:
TestLivewire.php

<?php

namespace App\Http\Livewire;

use Livewire\Component;

class TestLivewire extends Component
{
    public $testlw;

    public function render()
    {
        $this->testlw = "ok";
        return view('livewire.test-livewire');
    }
    public function activate()
    {
        $this->testlw = "NOPE";
        //dd($this->testlw);
    }
   
}

test-livewire.blade.php:

<x-slot name="header">
    <h2 class="font-semibold text-xl text-gray-800 leading-tight">
        Test wire:click.
    </h2>
</x-slot>

<div class="py-12">
    <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
        <div class="bg-white overflow-hidden shadow-xl sm:rounded-lg px-4 py-4">

            <div>
                Test: {{ $testlw }}
                <div>
                    <button wire:click="activate()"
                        class='bg-green-200 border font-bold rounded px-1 mx-1'>activate</button>                 
                </div>
            </div>
        </div>
    </div>
</div>

response:

{"effects":{"html":null,"dirty":[]},"serverMemo":
{"checksum":"353a06c25ed7ca131e8620ec46f7bb68136940ae15106ae92c7ab151c76f60af"}}

Hey, @nxd4n

You can do the following:

test-livewire.blade.php

<div wire:poll="activate">
  Test: {{$testlw}}
</div>
<button wire:click="activate">Activate</button>

Thanks, but this doesn’t help. It does every second an ajax call, but doesn’t update the variable.

I came across this https://laravel-livewire.com/docs/2.x/troubleshooting, would this apply to my case?

To answer to myself:
No

Edit:
Shouldn’t be there a variable “data”:

You must make the initial variable value into mount method or

public $testlw = "OK"

not in the render method

1 Like

Yes, thanks, I just found out by myself and was making a reply.

1 Like

I’m Happy to hear that,
Happy Coding mate :smiley:

1 Like

I have a similar problem, when I finish doing the emit event but the parameters on the blade are not updated, please maybe you can help?

I set the parameters in the controller

  • public $ latitude = “”, $ longitude = “”
    -in mount function
    $ this-> latitude = $ locationOne-> latitude;
    $ this-> longitude = $ locationOne-> longitude;
    // checked everything works

but when processing the emit function in the controller the processed data does not change to view