export default function App() { const [count, setCount] = useState(0); function set() { setCount(count + 1); } function undo() { setCount(count === 0 ? 0 : count - 1); } function resetToZero() { setCount(0); } function handleChange(event) { setCount(event.target.value); } return ( <div className="App"> <div className="Add"> <input id="count" value={count} onChange={handleChange}></input> <button onClick={set}> Add To Cart </button> <button onClick={undo}>Remove</button> <button onClick={resetToZero}>Remove All</button> </div> </div> ); }
What is "this"? It doesn't seem as your page is refreshing.
After I change the value of the input box using my keyboard and then pressing add to cart the number is not incrementing. Instead 1's are appending towards the end of the number.
It happened due to some other button. I removed it
Because your keyboard input is taken as string, and adding a number to a string results in a string, unless otherwise specifically handled.
Обсуждают сегодня