index.ts 808 B

1234567891011121314151617181920
  1. // 导入 redux
  2. import { applyMiddleware, legacy_createStore as createStore } from 'redux'
  3. // 导入自己封装的 rootReducer
  4. import rootReducer from './reducer'
  5. // 导入调试工具和 异步的 redux(用来发送异步请求)
  6. // 调试工具需要下载谷歌 扩展程序 我用的是 Redux DevTools 3.0.17
  7. import { composeWithDevTools } from 'redux-devtools-extension'
  8. import thunk from 'redux-thunk'
  9. // 创建仓库实例
  10. const store = createStore(rootReducer, composeWithDevTools(applyMiddleware(thunk)))
  11. // 声明 RootState,在使用仓库的时候用来使用
  12. export type RootState = ReturnType<typeof store.getState>
  13. // 声明 AppDispatch,在异步请求的时候来使用
  14. export type AppDispatch = typeof store.dispatch
  15. // 导出仓库实例
  16. export default store