Skip to content
Discussion options

You must be logged in to vote

I'd do:

queryClient.setQueriesData(
  ['my', 'fuzzy', 'key'],
  previous => previous?.id === myId ? updateWithImmer(...) : previous
)

so the idea is to run setQueriesData, which is fuzzy, and it will give you all "old" data for each matching key. Then, you can decide upon that if you want to perform an update or not. You can just return the previous data if it doesn't match what you are looking for.

Note that previous data can be potentially undefined (because you could match queries that are in loading state or have no data because they are disabled). The code I've shown also only works in v4 because only there, you can return undefined from the updater as well.

Replies: 1 comment 1 reply

Comment options

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

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