Skip to content

Using cached data after a request has failed #5780

Answered by TkDodo
brenocastelo asked this question in Q&A
Discussion options

You must be logged in to vote

React Query will not throw away cached data. If a background refetch fails, your Query should be in the following state:


{
  "status": "error",
  "error": <your error here>,
  "data": <stale data from the last successful fetch here>
}

One thing I'm seeing is that you are using fetch, but you're not handling errors in a way that Promises are rejected when the fetch returns 4xx or 5xx responses. This is a common gotcha:

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@brenocastelo
Comment options

Answer selected by brenocastelo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants