【发布时间】:2021-05-24 16:16:54
【问题描述】:
我正在尝试使用类型化来配置具有预加载状态的 Redux 存储。
Redux Toolkit TypeScript quick start guide 有这个例子:
import { configureStore } from '@reduxjs/toolkit'
const store = configureStore({
reducer: {
one: oneSlice.reducer,
two: twoSlice.reducer
}
})
// Infer the `RootState` and `AppDispatch` types from the store itself
export type RootState = ReturnType<typeof store.getState>
export type AppDispatch = typeof store.dispatch
不幸的是,在预加载状态下,它看起来更像这样:
export function initStore(preloadedState) {
const store = configureStore({
reducer: {
one: oneSlice.reducer,
two: twoSlice.reducer
},
preloadedState,
})
return store
}
我现在从哪里获得RootState 类型和AppDispatch 类型?
【问题讨论】:
标签: reactjs typescript redux types redux-toolkit