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
Uh oh!
There was an error while loading. Please reload this page.
-
I encountered an error in my app when an optimistic update didn't check to see if
prevCachewasundefinedwhen applying an optimistic update before a mutation. The app was in a state where the cache should have been populated and notundefinedso I'm wondering what are the reasons the query cache could becomeundefined? I'm usingreact-query2.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
useOptimisticMutationand it looks like this:An error occurs in
updatewhenprevCacheisundefinedand sorollbackis not returned and theonErrorultimately throws becauserollbackis not a function.The mutation is called from a
buttononClickhandler. The button is conditionally rendered if the collection which is being mutated is notisLoadingand 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
prevCacheto beundefinedinqc.setQueryData? I'd provide a reproducible example in Codesandbox but I only encountered this once. Really I'm looking for a deeper understanding of thequeryCachestate and what combination of factors might cause anundefinedvalue where there was once a correctly resolved value.Beta Was this translation helpful? Give feedback.
All reactions