Skip to content

How to Increment/Decrement a value in React/NextJS

Use the following code block to get started:

function GetCount() { const [count, setCount] = useState(1); const incrementCounter = () => { setCount(count+1) } const decrementCounter = () => { if (count>1) setCount(count-1) } return <div className="_counterWrapper"> <span className="_dec" onClick={() => decrementCounter()}>-</span> <span className="_val">{count}</span> <span className="_inc" onClick={() => incrementCounter()}>+</span> </div> }
Code language: JavaScript (javascript)

Then in your HTML code, add it like this:

<GetCount />
Code language: HTML, XML (xml)

See also  A Simplistic TCP Finite State Machine (FSM) in Python
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x