Skip to content
Discussion options

You must be logged in to vote

There's nothing special in React Query here - it's up to you to transform data in an immutable way. You can of course use immutable.js or something like immerjs if you want.

how do I call setQueryData() in the optimistic update to modify the label of ID 2?

I'd just do:

queryClient.setQueryData({
  ...previousData,
  items: previousData.items.map(item => item.id === id ? { ...item, label: newLabel } : item)
})

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by ffxsam
Comment options

You must be logged in to vote
0 replies
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