Put in order · JavaScript and React course · Module 10: React Ecosystem and Future

Query Lifecycle in TanStack Query

Order the query lifecycle in TanStack Query v5, from mounting the component to a background refetch:

Items to put in order

  • A trigger, e.g. returning to the tab: background refetch (fetchStatus fetching, status still success)
  • Mount with no data in the cache: status pending, fetchStatus fetching (isLoading)
  • New data in the cache: fetchStatus goes back to idle and the UI shows fresh data
  • Data arrives: status success, the data is fresh
  • staleTime passes: the data becomes stale but is still displayed

You can check the correct answer by solving this task in the CodeWorlds game.