In CreateApi for RTK Query
export const authApi = createApi({
reducerPath: 'authApi',
baseQuery: axiosBaseQuery({
baseUrl: environment.base_url
}),
endpoints: (builder) => ({
user: builder.query<any,void>({
query: () => ({
url: API.GET_USER_URL,
method: 'GET'
}),
transformResponse: (response: any) => response.data ?? []
})
})
})
export const { useUserQuery } = authApi;
export default authApi;
In CreateSlice
Inside extrareducers
builder.addMatcher(authApi.endpoints.user.matchFulfilled, (state, { payload }) => {
state.user = payload;
})
we can put data from RTK Query into user state via addMacher
Top comments (0)