const Counter = () => {
const [count, setCount] = useState(0);
// return <button onClick={setCount(count + 1)}>{count}</button>;
return <button onClick={() => setCount(count + 1)}>{count}</button>;
};
I'm aware that the commented out line causes an infinite loop but I want to know why that's the case. Isn't the setCount
dispatch function invoked only on click?