everyone. I'm learning react recently. I learned a lesson As this link says, the react function loads twice. But when I verified it, I found that it did load twice, but the Chrome browser only printed once. I wonder why? Here is the code I verified.
let count = 0;
function App() {
const [state, setState] = useState(1);
count++;
console.log(count);
console.log(`I have run ${count} time(s)!`);
return (
<div>
<button onClick={() => setState((e) => e + 1)}>{state}</button>
</div>
);
Here is the result of chrome execution
I think chrome should concole.log
1 App.js:9 I have run 1 time(s)! 2 App.js:9 I have run 2 time(s)!
I want to know why. Thank you.