The usual pitfalls are: race conditions (a slow old response overwrites a newer one), no cleanup or cancellation (setting state after unmount, wasted requests, Strict Mode double fetches), request waterfalls (parent fetches, then the child starts its fetch), missing loading/error/empty states, no caching or deduplication (the same data fetched by many components and refetched on every mount), unstable effect dependencies causing refetch loops, treating server data as local state (copying it into useState so it goes stale), and fetching in effects when the data could load earlier (in loaders, Server Components, or on user intent).
useEffect(() => {
let ignore = false;
fetchResults(query).then(data => {
if (!ignore) setResults(data); // drop stale responses
});
return () => { ignore = true; };
}, [query]);
Typing "re" then "react" quickly can resolve "re" last. Ignore stale responses, or abort them with AbortController (which also saves bandwidth).
Without cleanup, unmounted components still process responses, subscriptions leak, and in development Strict Mode's mount → unmount → mount cycle fires duplicate requests. Abort in the cleanup. Request deduplication is a caching concern, not a reason to disable Strict Mode.
function Page() {
const user = useFetch('/me'); // request 1
if (!user) return <Spinner />;
return <Orders userId={user.id} />; // request 2 starts only after 1 finishes and Orders renders
}
Fixes: fetch in parallel at the route level (loaders, Promise.all), prefetch on hover, start requests before rendering (render-as-you-fetch), or move fetching to Server Components close to the data. Lazy-loaded components that fetch create code + data waterfalls, so preload both.
useEffect(() => { fetchItems(filters); }, [filters]); // filters = {} created every render, so it loops
Depend on primitives, memoize, or move the object into the effect.
Handle loading, error, empty, and partial/refreshing states. Keep showing stale data while refetching instead of blanking to a spinner (placeholderData/keepPreviousData, or startTransition). Use skeletons to avoid layout shift.
Hand-rolled useEffect fetching gives each component its own copy: no sharing, no deduplication, no background revalidation, and a refetch whenever you navigate back. A server-state library (TanStack Query, SWR, RTK Query) or framework cache solves this, including invalidation after mutations.
const [name, setName] = useState(user.name); // diverges when user refetches
Keep server data in the cache as the source of truth, and keep only draft edits in local state, reset with a key when the entity changes.
response.ok: fetch only rejects on network errors, so a 404 or 500 "succeeds".useEffect(async () => …) returns a promise instead of a cleanup function. Define the async function inside the effect.use() without caching them, which suspends forever.response.ok checks.useState.Spotted a mistake or a rights concern? Report an issue