Aug 17, 2023
Certainty, if you'd like to use RTK query, so like this:
const api = createApi({
reducerPath: 'api',
baseQuery: fetchBaseQuery({ baseUrl: 'https://api' }),
endpoints: (builder) => ({
fetchData: builder.query({
query: () => '/data',
}),
}),
});
const { useFetchDataQuery } = api;
// store
const store = configureStore({
reducer: {
[api.reducerPath]: api.reducer,
},
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware().concat(api.middleware),
});
// in component
const { data, error, isLoading } = useFetchDataQuery();