Updating cached values of an array #6085
-
Imagine that you have a page that lists a bunch of records, and to load them you do this:
say I have a socket message which tells me that project ID 3 has changed its description. I mean, you could also invalidate the full cache of EDITED I was using it wrong, I fixed the getting function; when I asked the question it was:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
what is
you'd want to use |
Beta Was this translation helpful? Give feedback.
-
Sorry, I updated the question and the code. It was a bad paste.
And I get a notification that the record with ID 2 goes from "Michael" to "Matt". Ideally, I would update the cached array and only change the one with ID 2. I couldn't replace the whole array, since I wouldn't have the rest of the data (but only the fact that record ID 2 has changed). If I receive such a notification, the other option is to change the data in the List view, and then invalidate the cache altogether. Which seems wasteful, since we know what's changed... but maybe that's the easiest/sanest thing to do? |
Beta Was this translation helpful? Give feedback.
queryClient.setQueryData
has a functional updater, so you'd do: