【发布时间】:2021-11-18 17:55:43
【问题描述】:
我目前正在开发基于 Next.js 的 Web 应用程序。
我们正在使用 Next.js + Redux + Redux-Thunk。我问这个问题是因为开发过程中发生了错误。
'AsyncThunkAction
' 是 不可分配给“AnyAction”类型的参数。属性“类型”是 'AsyncThunkAction ' 但是 在“AnyAction”类型中是必需的。
在组件内,dispatch 通常接收 thunk 函数作为参数,但 store.dispatch() 不能接收 thunk 函数作为 getServerSideProps 函数的参数。
export const getServerSideProps = wrapper.getServerSideProps((store) => async () => {
store.dispatch(getPeoples(1));
return {
props: {
peoples: data,
},
};
}
);
这是我的store.tsx
const makeStore = () => configureStore({
reducer: rootReducer,
middleware: getDefaultMiddleware => getDefaultMiddleware(),
// devTools,
// preloadedState,
// enhancers:
});
export type AppStore = ReturnType<typeof makeStore>;
export type AppState = ReturnType<AppStore['getState']>;
export type AppThunk<ReturnType = void> = ThunkAction<ReturnType, AppState, unknown,
Action>;
export type AppThunkDispatch = ThunkDispatch<{}, void, AnyAction>
export default createWrapper(makeStore);
有好的解决办法吗?
【问题讨论】:
标签: reactjs typescript redux next.js redux-thunk