A React component can show data for the wrong selection when a user navigates quickly because network responses may arrive out of order. If a request for item A finishes after a request for item B, both completions can update state—and the late A result can replace B. In an Effect, prevent that by aborting obsolete work when possible or ignoring its result during cleanup.
How a late response replaces the current result
Imagine a component first fetches item A, then the user selects item B. The component starts a second request, but the network does not guarantee that requests finish in the order they started. If B returns first, the UI can show B; if A returns later and also calls a state setter, the UI can revert to A even though the current selection is B.
This is a response-ordering problem, not React rearranging requests. React’s useEffect reference notes that network responses may arrive in a different order than they were sent. Its search-results example describes the same issue with rapidly changing queries.
Ignore results from an obsolete Effect
React runs an Effect’s cleanup before setting it up again when a dependency changes, and when the component unmounts. Use that cleanup to mark the particular Effect instance as obsolete. Each setup gets its own flag, so a later request has a separate flag from an earlier one.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minute#1 Best Overall
useEffect(() => {
let ignore = false;
async function load() {
setData(null);
try {
const result = await fetchData(id);
if (!ignore) setData(result);
} catch (error) {
if (!ignore) setError(error);
}
}
load();
return () => {
ignore = true;
};
}, [id]);
When id changes, cleanup sets the old instance’s ignore flag to true. If that request later succeeds or fails, its completion cannot update the component’s state. Keep every reactive value used by the Effect in its dependency list; the example uses [id] because the request depends on id.
Reset loading or displayed data to match the interface you want while the new request is pending. Guard any state update that could be made irrelevant by navigation—including error state—with the same flag. This pattern prevents obsolete completions from affecting component state; it does not stop the underlying work.
Choose between ignoring and aborting
React documents both ignoring a result and aborting a fetch as valid cleanup strategies. Choose based on whether cancellation is supported and useful for the operation.
| Approach | What it does | When it fits |
|---|---|---|
| Ignore the result | Allows the work to continue but prevents its obsolete completion from updating state. | A straightforward state-correctness guard, including when the operation cannot be cancelled. |
| Abort the request | Attempts to cancel work when the request implementation supports cancellation. | Useful when stopping the client-side request is appropriate. A client abort cannot undo server work that has already happened. |
Whichever approach you use, the important part is that obsolete work cannot replace the current selection’s result. React’s Effect synchronization guide recommends that fetch cleanup either abort the fetch or ignore its result.
Rank #3
What Strict Mode’s extra request means
With Strict Mode enabled, React performs an extra setup-and-cleanup cycle for Effects in development before the actual setup. This checks whether cleanup mirrors setup. A duplicate-looking request in development does not, by itself, prove that the production UI has a stale-response bug. Check that cleanup correctly aborts or ignores the obsolete work, then verify which result the component displays.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.When an Effect is not the right data-loading layer
A component-local Effect can be adequate for a one-off synchronization. But manual fetching in Effects requires handling lifecycle details and does not automatically provide caching or other data-loading optimizations. If the app needs caching, request deduplication, server rendering, preloading, or fewer network waterfalls, React recommends using data-fetching mechanisms provided by a framework where available, or a client-side cache.
Rank #4
React names TanStack Query, useSWR, and React Router 6.4+ as examples of client-side data-fetching options. Follow the conventions of the framework or data layer your app already uses; the appropriate choice depends on the application’s needs.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →




