-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Description
Hello!
Recently I started using RTK Query and I have a problem with selecting data from the store after mutation. I don't understand what is the best way to do this.
For example, I have two components. I trigger mutation in the first component and I need to get results in the second component. I can't use the useMutation hook because it works fine only in one component. Also I don't want to put a useMutation hook to a parent.
My createAPI:
export const subscriptionApi = createApi({
reducerPath: 'subscribe/create',
baseQuery: fetchBaseQuery({ baseUrl: '/api' }),
tagTypes: ['Subscription'],
endpoints: (builder) => ({
getSubscriptionStatus: builder.query<Subscription, string>({
query: (serviceID: string) => `subscription/${serviceID}`,
}),
createSubscription: builder.mutation<Subscription, string>({
query: (serviceID: string) => ({
url: 'subscription/',
method: 'POST',
body: {
serviceID,
},
}),
}),
}),
});
export const { useGetSubscriptionStatusQuery, useCreateSubscriptionMutation } = subscriptionApi;My plan is to select the result from the store manually, but I don't know how I can do this the best way, because each request has a unique cache key. Please help me find any good solutions.
Metadata
Metadata
Assignees
Labels
No labels