Closed
Description
I am trying to manually add query data cache for each item in list, after loading whole list.
It's simple table view, after which I would like to have instant load on each details view for any of the items in the list.. And I can't make it work, seems like updateQueryData callback is not called.
Keep in mind that at the moment when getAll function gets called, there isn't any getById queryes in cache! I am not sure if that's issue here..
This is my api code for getAll(list view):
getAll: builder.query({
query: () => `getAll`,
providesTags: (result) =>
result
?
[
...result.map(({ id }) => ({ type: "Fruits", id })),
{ type: "Fruits", id: "LIST" },
]
: [{ type: "Fruits", id: "LIST" }],
async onQueryStarted(_, { dispatch, queryFulfilled }) {
try {
const { data } = await queryFulfilled;
//here I am getting my list...
data.map((fruit) => {
dispatch(
fruitApi.util.updateQueryData("getById", fruit.id, (draft) => {
console.log("hi mom");
return Object.assign(draft, fruit);
})
);
});
} catch (e) {
console.log(e);
}
},
}),
And this is my getById(details view) api code:
getById: builder.query({
query: (id) => `getById?id=${id}`,
providesTags: (result) =>
result
? [{ type: "Fruits", id: result.id }] : [],
}),
Metadata
Metadata
Assignees
Labels
No labels