useEffect is Executed Twice
Saturday, November 8, 2025
I had a case in which my react app calls the same api endpoint twice. The call is wrapped inside the useEffect hook. At first, I thought the page was rendered twice, but that was not the case.
useEffect(() => {
callEndpoint();
}, []);
After further investigation, apparently the useEffect is executed twice even though the trigger is an empty array. I found out later on that it is due to React.StrictMode. In my App.tsx:
<React.StrictMode>
<App />
</React.StrictMode>
Removing it removed the duplicate execution.
//<React.StrictMode>
<App />
//</React.StrictMode>