Wednesday, February 21, 2024
HomeSoftware EngineeringThe right way to Increment/Decrement a worth in React/NextJS

The right way to Increment/Decrement a worth in React/NextJS



Use the next code block to get began:
operate GetCount() { const [count, setCount] = useState(1); const incrementCounter = () => { setCount(depend+1) } const decrementCounter = () => { if (depend>1) setCount(count-1) } return <div className="_counterWrapper"> <span className="_dec" onClick={() => decrementCounter()}>-</span> <span className="_val">{depend}</span> <span className="_inc" onClick={() => incrementCounter()}>+</span> </div> } Then in your HTML code, add it like this:
<GetCount />

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments