what could cause a query cache value to become undefined? #2065
Unanswered
thebrengun
asked this question in
Q&A
Replies: 1 comment 2 replies
-
usually one of two things:
|
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I encountered an error in my app when an optimistic update didn't check to see if
prevCache
wasundefined
when applying an optimistic update before a mutation. The app was in a state where the cache should have been populated and notundefined
so I'm wondering what are the reasons the query cache could becomeundefined
? I'm usingreact-query
2.26.4Some more details: specifically this happened inside of a custom hook I use to apply optimistic updates before a mutation modified from the example docs. It's called
useOptimisticMutation
and it looks like this:An error occurs in
update
whenprevCache
isundefined
and sorollback
is not returned and theonError
ultimately throws becauserollback
is not a function.The mutation is called from a
button
onClick
handler. The button is conditionally rendered if the collection which is being mutated is notisLoading
and if the collection is truthy.The button logic is wrapped up in its own component like:
And is rendered in a component like
Finally, this happened in a private Chrome window which had recently been refocused and may have been refetching the query in the background.
What might be causing
prevCache
to beundefined
inqc.setQueryData
? I'd provide a reproducible example in Codesandbox but I only encountered this once. Really I'm looking for a deeper understanding of thequeryCache
state and what combination of factors might cause anundefined
value where there was once a correctly resolved value.Beta Was this translation helpful? Give feedback.
All reactions