I have an infinity scroll in my component. and I update the data in real-time using a web socket connection.
imagine I'm getting 10 items for each page and now I'm at page 2.
when I want to update one of the items in the 10 first items based on the web socket, I can not access to first 10 items because I'm on page 2, and with updateCachedData
I only have access to the result of page 2.
so how can I fix this?
page 1 = [{a: 1}, {b: 1}, {c: 1}];
page 2 = [{e: 1}, {f: 1}, {g: 1}];
when page = 2;
updateCachedData(draft => {
// draft shows [{e: 1}, {f: 1}, {g: 1}];
// but I need to update page 1 to [{a: 1}, {b: 5}, {c: 1}]
// so when the user back to page 1, he can see the updated value.
})
After reading the documentation and thanks to @markerikson I found updateQueryData
but it does not fire. what am I missing?
async onQueryStarted(
arg,
{
dispatch,
// getState,
// extra,
// requestId,
queryFulfilled
// getCacheEntry,
// updateCachedData
}
) {
try {
await queryFulfilled;
dispatch(
ApiSlice.util.updateQueryData('getOrderList', arg, (d) => {
console.log('draft', d);
})
);
} catch (er) {
console.log('er', er);
}
},
```