Skip to content

Commit 551f793

Browse files
authored
Add comment to makeStore
1 parent 44c13d6 commit 551f793

File tree

1 file changed

+19
-17
lines changed
  • packages/react-native-template-redux-typescript/template/src/app

1 file changed

+19
-17
lines changed
Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,42 @@
1-
import type { Action, ThunkAction } from "@reduxjs/toolkit"
2-
import { combineSlices, configureStore } from "@reduxjs/toolkit"
3-
import { setupListeners } from "@reduxjs/toolkit/query"
4-
import { counterSlice } from "../features/counter/counterSlice"
5-
import { quotesApiSlice } from "../features/quotes/quotesApiSlice"
1+
import type { Action, ThunkAction } from "@reduxjs/toolkit";
2+
import { combineSlices, configureStore } from "@reduxjs/toolkit";
3+
import { setupListeners } from "@reduxjs/toolkit/query";
4+
import { counterSlice } from "../features/counter/counterSlice";
5+
import { quotesApiSlice } from "../features/quotes/quotesApiSlice";
66

77
// `combineSlices` automatically combines the reducers using
88
// their `reducerPath`s, therefore we no longer need to call `combineReducers`.
9-
const rootReducer = combineSlices(counterSlice, quotesApiSlice)
9+
const rootReducer = combineSlices(counterSlice, quotesApiSlice);
1010
// Infer the `RootState` type from the root reducer
11-
export type RootState = ReturnType<typeof rootReducer>
11+
export type RootState = ReturnType<typeof rootReducer>;
1212

13+
// The store setup is wrapped in `makeStore` to allow reuse
14+
// when setting up tests that need the same store config
1315
export const makeStore = (preloadedState?: Partial<RootState>) => {
1416
const store = configureStore({
1517
reducer: rootReducer,
1618
// Adding the api middleware enables caching, invalidation, polling,
1719
// and other useful features of `rtk-query`.
18-
middleware: getDefaultMiddleware => {
19-
return getDefaultMiddleware().concat(quotesApiSlice.middleware)
20+
middleware: (getDefaultMiddleware) => {
21+
return getDefaultMiddleware().concat(quotesApiSlice.middleware);
2022
},
2123
preloadedState,
22-
})
24+
});
2325
// configure listeners using the provided defaults
2426
// optional, but required for `refetchOnFocus`/`refetchOnReconnect` behaviors
25-
setupListeners(store.dispatch)
26-
return store
27-
}
27+
setupListeners(store.dispatch);
28+
return store;
29+
};
2830

29-
export const store = makeStore()
31+
export const store = makeStore();
3032

3133
// Infer the type of `store`
32-
export type AppStore = typeof store
34+
export type AppStore = typeof store;
3335
// Infer the `AppDispatch` type from the store itself
34-
export type AppDispatch = AppStore["dispatch"]
36+
export type AppDispatch = AppStore["dispatch"];
3537
export type AppThunk<ThunkReturnType = void> = ThunkAction<
3638
ThunkReturnType,
3739
RootState,
3840
unknown,
3941
Action
40-
>
42+
>;

0 commit comments

Comments
 (0)