A disabled query returns stale data? #2180
Unanswered
JanStevens
asked this question in
Q&A
Replies: 1 comment 1 reply
-
if data is available in the cache, react-query will give it to you, no matter what. since you are in control of the enabled flag, you can always chose to not display that data if your query is disabled :) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi 👋 ,
I have a component that allows to search for
Contacts
and / orContactGroups
depending on two booleans:withContacts
andwithContactGroups
. The following code is used to fetchcontacts
andcontactGroups
:useContacts
anduseContactGroups
are a simple custom hook wrapper arounduseQuery
example:What I notice is that if I first open my component for showing groups (
withContacts: true, withContactGroups: true
) I see indeed only groups query being executed.I then navigate to another page and open the same component but with
withContacts: true, withContactGroups: false
I see that contacts query get executed but contactGroups query also returns it stale data even when its disabledNow my question is, is this expected behaviour or not, I'm I missing something obvious here?
I made a code sandbox to demo this behaviour: https://codesandbox.io/s/react-query-enabled-queries-3tiz9?file=/src/index.js
I would expect that if the query is disabled the return data is also
undefined
, but it returns the stale data instead.Beta Was this translation helpful? Give feedback.
All reactions