Cleanup and Race Conditions — Concept Check
Questions on Cleanup and Race Conditions. Every subscription needs a cleanup, and every fetch inside an effect needs to handle a response that arrived too late. Both are invisible in development and obvious to users.
Questions in this quiz
7 questions on Cleanup and Race Conditions — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A React component fetches data on mount and updates state. After a route change, the old request finishes after a new one. What issue arises?
- ABoth requests succeed with no issue
- BNew data is ignored
- CBoth requests fail
- DStale data overwrites new data
2.In a React component using `setInterval`, what happens if you forget to clear it on unmount?
- AComponent crashes
- BMemory leaks and stale behavior
- CNothing noticeable
- DInterval runs only once
3.You notice two fetch requests in the network tab for a single component mount in development. Why might this happen?
- ANetwork configuration issue
- BReact production bug
- CStrictMode double-invokes setups
- DComponent logic error
4.A developer uses a `hasRun` ref to suppress double fetches in StrictMode. Why is this a bad idea?
- APrevents race conditions
- BImproves performance
- CHides a real bug
- DReduces code complexity
5.When using `AbortController` with fetch, what benefit does it provide?
- ASpeeds up the request
- BStops the request itself
- CEnsures data consistency
- DPrevents all errors
6.Why might a component's event listeners accumulate over time?
- AToo many re-renders
- BMissing cleanup on re-runs
- CExcessive state updates
- DIncorrect prop usage
7.What is the purpose of a cleanup function in a React `useEffect` hook?
- ATo enhance component styling
- BTo stop ongoing processes
- CTo manage component state
- DTo start new processes