Simple counter example as a component class
See original GitHub issueSo I was trying to demo the concept of Sprig class components to a colleague with a simple example
<?php
namespace sprig\components;
use putyourlightson\sprig\base\Component;
class HelpSupport extends Component
{
public int $count = 2;
protected $_template = '_components/helpSupport';
public function updateCount()
{
$this->count = $this->count * 2;
}
}
and then the component
<div class="container"
id="helpSupport">
<form sprig
s-action="updateCount"
s-replace="#hello"
>
<button>
increase counter
</button>
</form>
</div>
<div id="hello">
{{ count }}
</div>
it works on the first click but then stops. What’s missing?
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top Results From Across the Web
Simple Counter App in React JS - with Functional and Class ...
We'll make a Simple Counter App in React JS - with Functional and Class Based Component. In this counter application, we've shown two...
Read more >A simple counter using React - CodeSandbox
This is a simple counter that displays the things that you can do with React component. 7. 257.6k.
Read more >How to Build a Simple Counter App in React - Techomoro
This is a simple guide to creating a simple counter app using React. It will help you to get an idea about React...
Read more >React Counter Button - Will Vincent
Let's build a simple counter button in React that will update every time it is clicked. To start, create a new React app...
Read more >React - Class Component for Counter - CodePen
1. class Counter extends React.Component { ; 2. constructor(props) { ; 3. super(props); ; 4. this.state = { ; 5. count: 0.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That
s-replace
crept back in somehow, removing it should work.Since we’re already doing this, here would be my version of a
counter
component.