I just integrated to redux-toolkit . My goal is to store the result of the query getPosts in a slice, so I can use it across the site or change it.
My createApi is like this:
export const postsApi = createApi({
reducerPath: "posts",
baseQuery: getGeneralFetchBaseQuery(),
endpoints: (builder) => ({
getPosts: builder.query<PostsType, number>({
query: (id) => `api/posts/${id}`,
}),
}),
});
export const { useGetPosts } = postsApi;
I want to store the result from getPosts in this slice
export const postsSlice = createSlice({
name: "posts",
initialState,
reducers: {},
});
export default postsSlice.reducer;
and my store is like this
export const mainStore = configureStore({
reducer: {
postsReducer,
[postsApi.reducerPath]: postsApi.reducer,
},
})
How can this be achieved?