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

Redux报错:Actions必须是纯对象,实际类型为Promise

问题解决:Actions must be plain objects. Instead, the actual type was: 'Promise'

问题原因

你触发dispatch(deleteCourse(course._id))时,传入的deleteCourse是API层的请求函数(返回Promise),而非Redux Action Creator(返回异步函数供thunk中间件处理),所以Redux会把这个Promise当成action,触发类型错误。你提到console.log deleteCourse显示是已resolved的Promise,也验证了这一点——你导入错了函数。

解决方案

  1. 修正组件中的导入语句
    确保组件里导入的是actions/courses.js中的Action Creator,而不是api/index.js中的API请求函数:
// 正确导入(Action Creator,返回异步函数)
import { deleteCourse } from '../actions/courses';

避免错误导入:

// 错误导入(API请求函数,返回Promise)
import { deleteCourse } from '../api';
  1. 检查根Reducer的导入与配置
    你的index.js中reducers的导入路径存在问题:
// 当前错误路径
import reducers from '../src/api/reducers';

如果你的根Reducer文件是src/reducers/index.js(用于组合所有子reducer),正确的导入路径应为:

import reducers from './reducers';

若还未创建根Reducer文件,需新建src/reducers/index.js来组合courses reducer:

// src/reducers/index.js
import { combineReducers } from 'redux';
import courses from './courses';

export default combineReducers({
  courses,
});

验证

在组件中打印deleteCourse,确认输出为[Function (anonymous)](Action Creator函数),而非Promise对象。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.14 17:31:00