AI

When fetching data asynchronously, requests can return out of order. If the user clicks 'Next' then 'Previous' quickly, the 'Next' request might finish after 'Previous', showing the wrong data.

Your Task:

  • Implement a 'stale' or 'cancelled' flag in the useEffect
  • Create a boolean variable ignore set to false
  • In the cleanup function, set ignore to true
  • Only update state if !ignore
TypeScript Solution
Loading...

Submit your code to see test results