maybe some of you can open my eyes.
I don't understand why in this code: https://codesandbox.io/s/use-state-renders-twice-6r1xl component App renders twice when mounted and clicking the button (console.log is called twice)
code:
export default function App() {
const [clicked, setClicked] = React.useState(false);
const handleClick = () => setClicked(!clicked);
console.log(clicked);
return <button onClick={handleClick}>click</button>;
}
result:
false
false
true
true
it's just a functional component hooking useState
!