I have a question regarding an anonymous function calling setState. I am trying to do a basic exercise (playground) where the number displayed on the button is increased when you click on it.
function Button() { const [state, setState] = useState(1); return <button onClick={() => setState(state+1)} >{state}</button>; } ReactDOM.render( <Button />, document.getElementById('mountNode'), ); I am confused why calling setState directly (instead of calling the anonymous function that calls the setState) does not work.
return <button onClick={setState(state+1)} >{state}</button>;