在 Typescripted Redux 中,我如何找到我的 root reducer 的类型?
In Typescripted Redux, how do I find my root reducer's type?
export const makeStore = () => {
const store = configureStore({
reducer: {
reducer,
growthReportSlice,
selectBarSlice,
},
....
return store;
};
const dummy = makeStore();
export const wrapper = createWrapper(makeStore, { debug: true });
export type AppDispatch = typeof dummy.dispatch;
// export type RootReducer = ReturnType<typeof reducer> &
// ReturnType<typeof growthReportSlice> &
// ReturnType<typeof selectBarSlice>;
export const useAppDispatch = () => useDispatch<AppDispatch>();
我只需要根减速器的返回类型,但我有 3 个减速器组合。我怎样才能得到正确的输入?
你快完成了,你只需要组合你的减速器。
import {combineReducers} from 'redux'
const rootReducer = combineReducers({
reducer,
growthReportsSlice,
selectBarSlice
})
type RootState = ReturnType<typeof rootReducer>
...
const store = configureStore({
reducer: rootReducer,
...
export const makeStore = () => {
const store = configureStore({
reducer: {
reducer,
growthReportSlice,
selectBarSlice,
},
....
return store;
};
const dummy = makeStore();
export const wrapper = createWrapper(makeStore, { debug: true });
export type AppDispatch = typeof dummy.dispatch;
// export type RootReducer = ReturnType<typeof reducer> &
// ReturnType<typeof growthReportSlice> &
// ReturnType<typeof selectBarSlice>;
export const useAppDispatch = () => useDispatch<AppDispatch>();
我只需要根减速器的返回类型,但我有 3 个减速器组合。我怎样才能得到正确的输入?
你快完成了,你只需要组合你的减速器。
import {combineReducers} from 'redux'
const rootReducer = combineReducers({
reducer,
growthReportsSlice,
selectBarSlice
})
type RootState = ReturnType<typeof rootReducer>
...
const store = configureStore({
reducer: rootReducer,
...