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

ndeblauw's avatar
Level 10

Strange behaviour in component

I've built a pretty simple Livewire component for a Counter (code below).

  • Pressing the + and - buttons works as expected, it updates the number in the tags.
  • Changing the counter by putting a value in the input also works.

PROBLEM: pressing the + or - buttons doesn't update the value of the counter in the text input field... even though it is supposed to be bound to the variable, which is proven as it works the other way around.

What am I not seeing/missing here?

PS1. It is not a caching issue. I checked that. PS2. I am aware that I can use the magical $set action instead of the two functions, but that doesn't change the situation (nor my question thus)

<div>
    <p>{{$counter}}</p>
    <button wire:click="increment()">+</button>
    <button wire:click="decrement()">-</button>

    <input wire:model.live="counter" type="text">
</div>
class Counter extends Component
{
    public $counter = 0;

    public function increment()  { 
      $this->counter++;
    }

    public function decrement()  { 
      $this->counter--;
    }

    public function render() {
        return view('livewire.counter');
    }
}
0 likes
5 replies
tykus's avatar

Your code, as posted, works. What else is happening on the Component / page?

ndeblauw's avatar
Level 10

@tykus That component is twice on the page, and there is another livewire component running on it. But even when disabling all that, and only keeping this component once, it still doesn't work here.

tykus's avatar
tykus
Best Answer
Level 104

@ndeblauw any console errors/warnings, e.g. Detected multiple instances of Alpine running?

Alpine ships with Livewire already, and will be included on any page that haas a Livewire component. You do not need a separate Alpine script tag

1 like
ndeblauw's avatar
Level 10

@tykus Oh my gosh, I should have know this... :blush: Yes, disabling the Alpine that was loaded in the template did the trick... Thank you for pointing this out!

mfoq's avatar

I have tested your code and it works fine as expected both being updated in the tag and value of the counter in the text input field

1 like

Please or to participate in this conversation.