Skip to content

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

Answered by Birkbjo
Wxwind asked this question in Q&A
Discussion options

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

Comment options

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

Answer selected by TkDodo
Comment options

You must be logged in to vote
2 replies
@TkDodo
Comment options

@rohit-sqboat
Comment options

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