I have the following code:
// App.js
import { useEffect } from "react";
let count1 = 0;
function App() {
console.log("render");
console.log("before", count1);
count1 += 1;
useEffect(() => console.log("effect", count1));
console.log("after", count1);
return <button></button>;
}
export default App;
// index.js
import { StrictMode } from "react";
import ReactDOM from "react-dom";
import App from "./App";
const rootElement = document.getElementById("root");
ReactDOM.render(
<StrictMode>
<App />
</StrictMode>,
rootElement
);
After initial rendering, The console result in Chrome is:
I don't know why the value of count1 is 2 at last.

HookuseEffect. And this by default runs both after the first render and after every update.