🚨 React Interview Scenario (Real World) You have a component that fetches data from an API. useEffect(() => { fetchData(); }, []); Everything works fine… But suddenly: 👉 API is called multiple times 👉 Even though dependency array is empty 👀 Why is this happening? 👉 How would you fix it? Bonus: What changes in production vs development? #ReactJS #FrontendInterview #ReactHooks #JavaScript #FrontendDeveloper #WebDevelopment
In development phase react uses strict mode but in production api call only once
I prefer using React Query, which handles caching and avoids redundant API calls.
Typical React Strict Mode behavior Why -- In dev- React Strict Mode intentionally runs certain hooks twice to detect unexpected side effects and ensure the code is safe. In production- This doesn’t happen in production