The old request is still in flight when the query changes, so a slow response can land last and overwrite the fresh one. Give every request its own AbortController and cancel it when the effect cleans up.
- Abort, don’t ignore. The browser drops the response, so nothing parses late.
- Swallow the AbortError. It is expected, not a failure.
- Keep the query in the deps, so each keystroke cleans up the last call.
useEffect(() => { const ctrl = new AbortController(); fetch(url(query), { signal: ctrl.signal }) .then((r) => r.json()) .then(setResults) .catch(() => {}); return () => ctrl.abort(); }, [query]);
The same pattern works for any effect that loads data.