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

使用useSelector时出现'action is undefined'错误求助

解决useSelector触发的'action is undefined'错误

问题根源

你在PostsList.js第30行调用dispatch时,直接传入了action creator函数fetchPosts,而非调用该函数返回的action对象。Redux要求dispatch的参数必须是带type字段的普通对象(即action),直接传未执行的函数会导致Redux无法识别有效action,进而抛出action is undefined错误。

修复代码

把第30行的代码:

dispatch(fetchPosts);

改成:

dispatch(fetchPosts());

额外提示

如果fetchPosts是异步action creator(比如基于Redux Thunk实现),请确认你的store已配置Thunk中间件。不过当前报错的核心原因还是action creator未执行,导致传入dispatch的不是合法action对象。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.25 02:24:10