Persisted data removal on error #3623
-
Hello guys and thank you for this awesome library. I'm really not sure if this is a bug or not. Let me explain :
I find these two behaviors inconsistent with one another. What if my API is having issues and I want the user to still get the old data even after reloading the app ? I could then, use the error state to warn the user that we are experiencing issues. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 12 replies
-
@TkDodo already created a great blog post, in which he present the idea to show the data first, maybe that will help, PTAL: https://tkdodo.eu/blog/status-checks-in-react-query |
Beta Was this translation helpful? Give feedback.
-
but you can change that to e.g. thinking about it, this might even be the "better" default implementation, we could change that for v4 🤔 |
Beta Was this translation helpful? Give feedback.
data
is never deleted due to a background fetch, even if it fails, as you might want to prefer showing stale data.error
state though, and only queries that are insuccess
state will be persisted. This can be customized by passingshouldDehydrateQuery
todehydrateOptions
. The default is:https://github.com/tannerlinsley/react-query/blob/5848fab8a560efcf66ef0062c207c3004bccad83/src/core/hydration.ts#L72-L74
but you can change that to e.g.
!!query.state.data
to include all queries that have data, even erroneous ones.thinking about it, this might even be the "better" default implementation, we could change that for v4 🤔