i'm creating a react app with useMemo
.
The memo uses empty array as the dependency list, so it should be executed once, right?
Inside the memo, there are console.log()
& counter++
to visualize how many times the memo get executed.
Magically, I got one log but the counter seems executed twice.
See this sandbox or see the code below:
import {
useMemo,
} from 'react'
let counter = 0;
export default function App() {
const foo = useMemo(() => {
console.log('increase counter');
counter++;
}, []);
return (
<p>
{counter}
</p>
);
}