These systems aren’t controlled by React, so they are called external. An Effect lets you keep your component synchronized with some external system. such as:
A timer managed with setInterval() and clearInterval().
An event subscription using window.addEventListener() and window.removeEventListener().
Connection to network
some browser API, or
a third-party library, A third-party animation library with an API like animation.start() and animation.reset().
You need to fetch a user's profile when a component mounts and store it in state. How would you write the useEffect for that?
Describe how you would add a window resize listener in a component and ensure it is removed when the component unmounts.
If you omit the dependency array in a useEffect that fetches data, what will happen on each re‑render?
A chat widget should open a WebSocket when the user opens the chat and close it when they leave. Walk me through the useEffect implementation and any edge cases you’d watch for.
We want to debounce an API call based on user typing. How can you coordinate the timer with useEffect and guarantee the timer is cleared correctly?
During a review you see a useEffect that fetches data but doesn’t list the fetch function in its dependency array, causing stale results. How would you fix it and why?
Our dashboard renders dozens of widgets, each polling a different endpoint with setInterval inside useEffect. How would you design the effect to avoid memory leaks and unnecessary re‑renders at scale?
We need to integrate a third‑party analytics library that requires one‑time initialization and also needs to react to route changes. How would you structure useEffect(s) to handle both without duplicate initializations?
Explain how you would test that a component correctly synchronizes with an external subscription using useEffect, covering cleanup and potential race conditions.
Our codebase is moving from class components to hooks. What guidelines would you set for converting lifecycle methods that interact with external services (e.g., componentDidMount/WillUnmount) to useEffect, and how would you enforce consistency across teams?
We plan to introduce a global state solution that relies on external event streams. How would you architect useEffect usage across many components to avoid redundant subscriptions and centralize cleanup while keeping performance and bundle size in mind?
Discuss the trade‑offs of extracting side‑effect logic into custom hooks versus keeping it inline, especially when dealing with complex external systems like websockets or IndexedDB.