import { createStore , applyMiddleware , combineReducers , Action , Store , } from "redux" ; import { MakeStore , createWrapper } from "next-redux-wrapper" ; import thunkMiddleware from "redux-thunk" ; import storage from "redux-persist/lib/storage" ; import { persistReducer } from "redux-persist" ; import { composeWithDevTools } from "redux-devtools-extension" ; import authReducer from "./auth/reducer" ; const combinedReducer = combineReducers ( { authReducer , } ) ; export type RootState = ReturnType < typeof combinedReducer > ; const bindMiddleware = ( middleware ) => { if ( process . env . NODE_ENV !== "production" ) { return composeWithDevTools ( applyMiddleware ( ... middleware ) ) ; } return applyMiddleware ( ... middleware ) ; } ; const makeStore = ( { isServer } ) => { if ( isServer ) { return createStore ( combinedReducer , bindMiddleware ( [ thunkMiddleware ] ) ) ; } const persistConfig = { key : "nextjs" , whitelist : [ "authReducer" ] , storage , } ; const persistedReducer = persistReducer ( persistConfig , combinedReducer ) ; const store = createStore ( persistedReducer , bindMiddleware ( [ thunkMiddleware ] ) ) ; return store ; } ; export const wrapper = createWrapper ( makeStore ) ;