You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Redux ToolKit配置报错:TypeError: 无法读取undefined的'value'属性

问题排查与解决

核心原因

你的Redux Store未正确注册ediSlice对应的reducer,导致state.edi不存在,进而访问state.edi.value时触发Cannot read properties of undefined错误。虽然dispatch动作能看到payload,但状态并未真正存入Redux Store。

修复步骤

  1. 打开src/app/store.js,修改configureStore的配置,将ediSlice的reducer添加到store的reducers对象中:
import { configureStore } from '@reduxjs/toolkit';
// 导入ediSlice的reducer
import ediReducer from '../features/edi/ediSlice';

export const store = configureStore({
  reducer: {
    // 注册edi reducer,key为edi,对应useSelector中的state.edi
    edi: ediReducer,
  },
});
  1. 保存后重新运行项目,此时SendEdi.js中的const edicontent = useSelector((state) => state.edi.value);就能正确获取到初始状态"Hello World",以及后续更新的内容。

补充说明

之前你看到dispatch的payload更新,只是Redux ToolKit生成的action被正常创建,但因为没有对应的reducer处理并将状态存入store,所以store中根本没有edi这个状态节点,自然无法通过useSelector读取。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.17 06:40:43