Question about optimistic updates / freezing #507
-
I have a question regarding optimistic updates... Given the following mutation (removing a user from a list)
The issue is that some other component receives the users as prop and sorts it, which does not work when the cache is updated via setQueryData (it seems to be freezing the array). The component re-renders and I get an 'TypeError: Cannot assign to read only property '0' of object '[object Array]':
Is this expected? How would I best handle this? Making a copy of the array and passing this to the component? If I comment out the setQueryData part (basically removing optimistic update) everything works fine. Thanks for your time! (loving react-query btw, it's so good) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
This seems like it should work just fine, which tells me only one thing... we need a codesandbox for this use case to test it out in an isolated env. Would you be able to do that? |
Beta Was this translation helpful? Give feedback.
-
You can ignore all this, I swear I had checked the result from immer, but the produce method is what's freezing the array. Carry on. My bad. |
Beta Was this translation helpful? Give feedback.
You can ignore all this, I swear I had checked the result from immer, but the produce method is what's freezing the array. Carry on. My bad.