You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Make undefined an illegal cache value (for successful queries) #2925
This is an ever-recurring issue that you can't bail out of updates with setQueryData. But because the updater function gives you a potentially undefined value (if there is no cache entry for the key yet), TypeScript is very unhappy because you're supposed to create a new cache entry, and there is no "bailing out of it" because react-query actually creates the cache entry before the functional updater of setQueryData is called.
While we're at it: what should the type of setQueriesData be? If it only traverses existing queries, I guess it should use Updater<TData, TData> and not Updater<TData | undefined, TData> or Updater<TData | undefined, TData | undefined> (the latter is what the linked PR gives).
Activity
kayvaninvemo commentedon Jan 8, 2022
I face the same issue, I guess that the following code should be valid code:
neongreen commentedon Jan 30, 2022
While we're at it: what should the type of
setQueriesDatabe? If it only traverses existing queries, I guess it should useUpdater<TData, TData>and notUpdater<TData | undefined, TData>orUpdater<TData | undefined, TData | undefined>(the latter is what the linked PR gives).TkDodo commentedon Jan 30, 2022
@neongreen A query could exist but still have undefined data in the cache, e.g. if it's in idle or error state. So the latter is correct.
tannerlinsley commentedon Feb 9, 2022
🎉 This issue has been resolved in version 4.0.0-alpha.11 🎉
The release is available on:
Your semantic-release bot 📦🚀
tannerlinsley commentedon Apr 2, 2022
🎉 This issue has been resolved in version 4.0.0-beta.1 🎉
The release is available on:
Your semantic-release bot 📦🚀