Error: Actions must be plain objects. Use custom middleware for async actions. 的解决

一、问题的出现:

  1. 在进行 react 项目开发的时候,出现了这个错误,Error: Actions must be plain objects. Use custom middleware for async actions. 如下图所示:

在这里插入图片描述

二. 问题的分析及解决:

  1. 问题的分析:这个实际上是异步操作缺少使用自定义中间件,需要使用中间件 redux-thunk
  2. 问题的解决:通过 npm i redux-thunk --save 命令下载 redux-thunk,然后进行配置使用,如下所示:
import {
    
     createStore, compose, applyMiddleware } from 'redux'
import thunk from 'redux-thunk'
import reducer from './reducer'

const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose
const store = createStore(reducer, composeEnhancers(applyMiddleware(thunk)))

export default store

猜你喜欢

转载自blog.csdn.net/weixin_42614080/article/details/113619445
今日推荐