You need to enable JavaScript to run this app. React-Redux开发登录功能时遇store.getState is not a function报错求助
优惠活动
大模型
产品
解决方案
定价
更多

React-Redux开发登录功能时遇store.getState is not a function报错求助

store.getState is not a function 报错排查思路
  • 优先排查Provider组件的store属性传参错误
    • 当前index.js中<Provider store="{store()}">存在两处错误:
      • 给store属性添加了双引号,传入的是字符串而非store变量
      • store/index.js导出的是createStore直接返回的store实例,并非返回store的函数,无需加()调用
    • 正确传参格式为:<Provider store={store}>
  • 排查导入导出规范混用问题
    • index.js使用require(CommonJS规范)导入store,但store/index.js使用export default(ES Module规范)导出,二者混用可能导致导入结果异常,建议统一规范:改用import store from './store/index'导入
  • 排查文件路径匹配错误
    • store/reducers/AllReducers.js中导入路径为./AuthReducer,但实际文件名是AuthReducers.js,路径不匹配会导致后续reducer加载失败,需修正文件名或导入路径
  • 补充说明:redux-thunk配置问题不会触发当前报错,后续开发登录功能时再通过applyMiddleware配置即可

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.24 02:36:04