Skip to content

setQueryData set a new array doesn't refresh component #5967

Answered by Birkbjo
Wxwind asked this question in Q&A

You must be logged in to vote

This is because of structuralSharing and because you are mutating the old value, it's reusing the same data for performance reasons. You shouldn't mutate your old data.

Your example would work if you did structuralSharing: false for your useQuery in useGetNums. Or even

    structuralSharing: (oldData, newData) =>
      oldData === newData ? oldData : newData,

But that's basically the same thing as structuralSharing: false.

More info about structural sharing

Replies: 2 comments 3 replies

You must be logged in to vote
1 reply
@Wxwind

Answer selected by TkDodo

You must be logged in to vote
2 replies
@TkDodo

@rohit-sqboat

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants