Why I get this error on RTK Query when using onQueryStarted ? When I remove onQueryStarted then it works...
Possible Unhandled Promise Rejection (id: 0):
TypeError: Cannot destructure undefined
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/dist/query/react";
// @ts-ignore
import { API_ENDPOINT } from '@env';
import { IProduct } from "../../../components/Product";
export const WishlistApi = createApi({
reducerPath: 'WishlistApi',
baseQuery: fetchBaseQuery({baseUrl: `${API_ENDPOINT}/`}),
tagTypes: ['WISHLIST', 'HOME'],
endpoints: (build) => ({
homeList: build.query<(IProduct & { is_wishlist: boolean; })[], void>({
query: (data) => ({
url: '/home',
method: 'POST',
body: data
}),
providesTags: ['HOME']
}),
removeWishlist: build.mutation<void, void>({
query: () => ({
url: '/remove_wishlist',
method: 'POST',
body: 1
}),
async onQueryStarted({ }, { dispatch, queryFulfilled }) {
console.log(queryFulfilled);
const patchResult = dispatch(
WishlistApi.util.updateQueryData('homeList', undefined, (draft) => {
console.log(draft);
})
)
try {
await queryFulfilled
} catch {
patchResult.undo()
}
},
invalidatesTags: ['WISHLIST']
})
})
});
export const {
useHomeListQuery,
useRemoveWishlistMutation
} = WishlistApi;
i am very thankful for your help!!
.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,