You need to enable JavaScript to run this app. Next.js配置Redux时报TypeError: nextCallback is not a function如何解决?
优惠活动
大模型
产品
解决方案
定价
更多

Next.js配置Redux时报TypeError: nextCallback is not a function如何解决?

错误根因
  • 核心原因是next-redux-wrapper v7+ 版本对getServerSideProps的封装逻辑有强制要求:被wrapper.getServerSideProps包裹的回调函数必须返回符合Next.jsgetServerSideProps规范的返回值结构(即包含props字段的对象,或redirect/notFound等控制字段)。当前代码在执行完dispatch后没有任何返回值,框架内部接收不到预期的回调参数就触发了nextCallback is not a function的类型错误。
  • 附加潜在问题:配置的根reducer中保留了模板代码里的count状态校验逻辑,但实际合并的reducer只有Room字段,不存在state.count,后续运行到这行代码时还会抛出读取undefined属性的错误。
修复步骤
  1. 修改页面的getServerSideProps代码,执行完dispatch后补充必填的返回值:
export const getServerSideProps = wrapper.getServerSideProps(
  async ({ store }) => {
    await store.dispatch(getAllRooms());
    // 补充符合规范的返回对象
    return {
      props: {}
    };
  }
);
  1. 清理Redux配置文件中多余的模板代码,删除不存在的count状态相关逻辑:
const reducer = (state, action) => {
  if (action.type === HYDRATE) {
    return {
      ...state,
      ...action.payload,
    };
  }
  return combinedReducer(state, action);
};

修改完成后重启项目即可解决报错。

内容的提问来源于stack exchange,提问作者Rawand122

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.11 04:42:03