Loading…
A short voice session: one question, one follow-up, then instant feedback — up to 5 minutes.
Responses can arrive out of order, so an older request finishes last and overwrites newer data; ignore stale responses with a cleanup flag or abort them with AbortController.
Each userId change starts a new request, but the network does not guarantee responses come back in order. If the request for user A finishes after the one for user B, it sets state with A's data while B is selected. In the effect, declare let ignore = false, check it before setting state, and set ignore = true in the cleanup; or create an AbortController, pass its signal to fetch, abort in the cleanup, and do not treat the abort as an error. Libraries such as TanStack Query handle this, along with caching and retries, automatically.