index.ts
648 字节
import { configureStore } from "@reduxjs/toolkit";
import { useSelector, useDispatch, TypedUseSelectorHook, shallowEqual } from 'react-redux'
import counterReducer from './modules/counter'
const store = configureStore({
reducer: {
counter: counterReducer
}
})
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