TanStackT
TanStack2y ago
15 replies
rubber-blue

How to update the state of a paged query manually?

My items are fetched from multiple sources and combined into one sorted list in a RQ store, where each source is a group, so I need to update the cache manually at the sorted index. Should I just use onSuccess to do this? how do I prevent the default append that RQ does on response?

Example:
const response = ['dog', 'cat', 'bird', /* new type */ 'car', 'truck', 'ship', /* new type */ 'apple', 'orange', 'lemon']

// Then, user clicks on "load more animals" and the API will query page-2 for just animals, so cache should be updated like this:
oldDataDraft.splice(4, 0, ...newAnimals)
Was this page helpful?