|
1 |
| -import { combineReducers, configureStore } from '@reduxjs/toolkit' |
2 |
| -import type { PreloadedState } from '@reduxjs/toolkit' |
3 |
| -import { pokemonApi } from './services/pokemon' |
4 |
| - |
5 |
| -const rootReducer = combineReducers({ |
6 |
| - [pokemonApi.reducerPath]: pokemonApi.reducer, |
7 |
| -}) |
8 |
| - |
9 |
| -export const setupStore = (preloadedState?: PreloadedState<RootState>) => { |
10 |
| - return configureStore({ |
11 |
| - reducer: rootReducer, |
12 |
| - middleware: (getDefaultMiddleware) => |
13 |
| - // adding the api middleware enables caching, invalidation, polling and other features of `rtk-query` |
14 |
| - getDefaultMiddleware().concat(pokemonApi.middleware), |
15 |
| - preloadedState, |
16 |
| - }) |
17 |
| -} |
18 |
| - |
19 |
| -export type RootState = ReturnType<typeof rootReducer> |
20 |
| -export type AppStore = ReturnType<typeof setupStore> |
21 |
| -export type AppDispatch = AppStore['dispatch'] |
| 1 | +import { combineReducers, configureStore } from '@reduxjs/toolkit' |
| 2 | +import type { PreloadedState } from '@reduxjs/toolkit' |
| 3 | +import { pokemonApi } from './services/pokemon' |
| 4 | + |
| 5 | +const rootReducer = combineReducers({ |
| 6 | + [pokemonApi.reducerPath]: pokemonApi.reducer, |
| 7 | +}) |
| 8 | + |
| 9 | +export const setupStore = (preloadedState?: PreloadedState<RootState>) => { |
| 10 | + return configureStore({ |
| 11 | + reducer: rootReducer, |
| 12 | + middleware: (getDefaultMiddleware) => |
| 13 | + // adding the api middleware enables caching, invalidation, polling and other features of `rtk-query` |
| 14 | + getDefaultMiddleware().concat(pokemonApi.middleware), |
| 15 | + preloadedState, |
| 16 | + }) |
| 17 | +} |
| 18 | + |
| 19 | +export type RootState = ReturnType<typeof rootReducer> |
| 20 | +export type AppStore = ReturnType<typeof setupStore> |
| 21 | +export type AppDispatch = AppStore['dispatch'] |
0 commit comments