Skip to content

useQuery: When a value at query key changes and that changed value results to the false in enabled option, the returned data becomes initialValue(undefined in this case). #6062

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

You must be logged in to vote

Is this an expected behavior?

yes.

the false value in the enabled option is used to disable this query from automatically running.

that's true.

But here it is also overwriting the value of data to initialValue.

that's not what's happening. You have two Queries in the cache. You should be able to see that when using the devtools.

  • one query has the key ["100"] and the data {data: true}
  • the other has the key [""] and the value undefined

when you tell useQuery: Please give me data for key [""], it will give you what is in the cache, which is undefined. Usually, it would go and fetch the data for you, but not if its disabled.

So, bottom line: if you change the key, you observe a differ…

Replies: 1 comment 1 reply

Comment options

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

Answer selected by surajpheudin
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