index.ts 716 字节
import { configureStore } from "@reduxjs/toolkit";
import { useSelector, useDispatch, TypedUseSelectorHook, shallowEqual } from 'react-redux'
import counterReducer from './modules/counter'
import orderReducer from './modules/order'

const store = configureStore({
  reducer: {
    counter: counterReducer,
    order: orderReducer
  }
})

type GetStateFnType = typeof store.getState
type RootState = ReturnType<GetStateFnType>
type DispatchType = typeof store.dispatch

// 拿到 redux 内定义的变量的类型
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector
export const useAppDispatch: () => DispatchType = useDispatch
export const shallowEqualApp = shallowEqual

export default store