We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I am using createApi to define a base API and then injecting additional endpoints using injectEndpoints.
createApi
injectEndpoints
I have:
baseApi
getUserInformation
getUserOrders
Now, I want to reset the state for:
productApiService
userApiService
while keeping getUserInformation state untouched.
baseApi.util.resetApiState()
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react"; export const baseApi = createApi({ reducerPath: "baseApi", baseQuery: fetchBaseQuery({ baseUrl: "/api" }), endpoints: () => ({}), });
import { baseApi } from "./baseApi"; export const userApiService = baseApi.injectEndpoints({ endpoints: (builder) => ({ getUserInformation: builder.query({ query: () => "/user/info", }), getUserOrders: builder.query({ query: () => "/user/orders", }), }), }); export const { useGetUserInformationQuery, useGetUserOrdersQuery } = userApiService;
import { baseApi } from "./baseApi"; export const productApiService = baseApi.injectEndpoints({ endpoints: (builder) => ({ getProducts: builder.query({ query: () => "/products", }), }), }); export const { useGetProductsQuery } = productApiService;
Currently, if I use:
dispatch(baseApi.util.resetApiState());
It resets everything, including getUserInformation, which I want to keep intact.
dispatch(baseApi.util.resetApiState(productApiService.reducerPath)); // Example API
dispatch(baseApi.util.resetApiState(userApiService.endpoints.getUserOrders.name));
Is there any recommended workaround for this scenario?
Thanks! 🚀
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Need a way to reset state for specific injected API service or endpoints
Description
I am using
createApi
to define a base API and then injecting additional endpoints usinginjectEndpoints
.I have:
baseApi
)getUserInformation
getUserOrders
baseApi
)Now, I want to reset the state for:
productApiService
getUserOrders
fromuserApiService
while keeping
getUserInformation
state untouched.Current Behavior
baseApi.util.resetApiState()
resets the entire API state, including all services and endpoints.Expected Behavior
productApiService
).getUserOrders
) while leaving others (getUserInformation
) untouched.Code Example
baseApi.ts
userApiService.ts
productApiService.ts
Problem: How to Reset Product API and
getUserOrders
Only?Currently, if I use:
It resets everything, including
getUserInformation
, which I want to keep intact.Proposed Feature Request
Is there any recommended workaround for this scenario?
Thanks! 🚀
The text was updated successfully, but these errors were encountered: