store.ts 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import { configureStore } from "@reduxjs/toolkit";
  2. import cartSlice, {CartState} from "./slices/cart-slice";
  3. import addToCartDialogReducer from "./slices/addToCartDialogSlice";
  4. // export const store = configureStore({
  5. // reducer: {
  6. // cartDetail: cartSlice,
  7. // user: userSlice,
  8. // addToCartDialog: addToCartDialogReducer,
  9. // currencyList: currencySlice
  10. // },
  11. // });
  12. // export type RootState = ReturnType<typeof store.getState>;
  13. // export type AppDispatch = typeof store.dispatch;
  14. export interface PreloadedStateType {
  15. cartDetail: CartState;
  16. }
  17. export const makeStore = (preloadedState: PreloadedStateType) => {
  18. return configureStore({
  19. reducer: {
  20. cartDetail: cartSlice,
  21. addToCartDialog: addToCartDialogReducer,
  22. },
  23. preloadedState
  24. });
  25. }
  26. // Infer the type of makeStore
  27. export type AppStore = ReturnType<typeof makeStore>
  28. // Infer the `RootState` and `AppDispatch` types from the store itself
  29. export type RootState = ReturnType<AppStore['getState']>
  30. export type AppDispatch = AppStore['dispatch']