Replies: 1 comment 17 replies
-
As you said, we've been there before :) One of the issues you've linked was also opened by me a long time ago :) The current implementation is made that if you call
That is also my approach, because with TypeScript, it's very hard to work with the The problem could be in the details: looking at the code, we build a cache entry first, and then call setData on it: since |
Beta Was this translation helpful? Give feedback.
-
I have two different queries in my app. One query gets messages and one gets conversations.
Each conversation object needs to get populated with the last received message, if any. After the messages are fetched, I look through the conversations cache and then update it appropriately.
When the app started up, the messages query would fire before the first conversations query, so
existingConversations
would be undefined. This undefined value then gets written to the conversations cache. For some reason, this then causes the query function for 'conversations' to never fire. That is, React Query never marks the undefined conversation cache as stale.Once I realized this, the workaround was easy: don't use an updater function. So the correct code is:
I would like other users to avoid this issue, since it caused me a lot of pain and head-scratching. One idea: if the updater function returns
undefined
, do not set the cache data. If this seems like the right approach, I am happy to make a PR for it.The combination of the updater function and undefined caches has come up many times. Here are the related discussions and issues:
queryCache.hasQueryData
#486I am starting to wonder if having an updater function syntax is a good idea or not. It was created to be "convenient", but the issues with Typescript and undefined caches make it seem less than ideal.
Beta Was this translation helpful? Give feedback.
All reactions