Reactjs 错误:操作必须是普通对象。使用自定义中间件进行异步操作

Reactjs 错误:操作必须是普通对象。使用自定义中间件进行异步操作,reactjs,redux,axios,middleware,redux-thunk,Reactjs,Redux,Axios,Middleware,Redux Thunk,我有下面的代码,抛出的错误的行动必须是普通的对象。我认为问题是与redux thunk,但我不能纠正它 动作文件- import axios from "axios"; export const addBiller = (biller = {}) => { return async dispatch => { const res = await axios.post("/api/biller", biller); dispatch({ type: "ADD_BILLER", pay

我有下面的代码,抛出的错误的行动必须是普通的对象。我认为问题是与redux thunk,但我不能纠正它

动作文件-

import axios from "axios";
export const addBiller = (biller = {}) => {
return async dispatch => {
const res = await axios.post("/api/biller", biller);

dispatch({ type: "ADD_BILLER", payload: res.data });
};
};
我的商店-

import { createStore, combineReducers, applyMiddleware } from "redux";
import billerReducer from "../reducers/Billers";
import userReducer from "../reducers/User";
import billReducer from "../reducers/Bills";
import authReducer from "../reducers/Auth";
import reduxThunk from "redux-thunk";
export default () => {
 const store = createStore(
combineReducers(
  {
    Billers: billerReducer,
    Users: userReducer,
    Bills: billReducer,
    Auth: authReducer
  },
  applyMiddleware(reduxThunk)
  )
  );
 return store;
 };
后端文件-

 const mongoose = require("mongoose");
 const Biller = mongoose.model("biller");
 module.exports = app => {
 app.post("/api/biller", async (req, res) => {
 const { billerName, billerDescription } = req.body;
 const biller = new Biller({
  billerName: billerName,
  billerDescription: billerDescription
  });
   biller = await biller.save();
    res.send(biller);
    });
     };
我的减速机-

   const BillerDefaultState = [];
   const billerReducer = (state = BillerDefaultState, action) => {
    switch (action.type) {
    case "ADD_BILLER":
     return [...state, action.biller];
     default:
      return state;
     }
     };
     export default billerReducer;

看起来这是Thunk初始化到存储中的方式-增强器应该是第三个参数

createStore(reducer、[预加载状态]、[增强器])

[增强器](函数):存储增强器。您可以选择指定它以使用第三方功能(如中间件、时间旅行、持久性等)增强存储。Redux附带的唯一存储增强程序是applyMiddleware()

下面是我在项目中初始化它的方式,注意我以与您在代码中定义的方式相似的方式导入了
reducers
对象:

import { createStore, applyMiddleware, compose } from 'redux'
import reduxThunk from 'redux-thunk'

const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose
const store = createStore(reducers, {}, composeEnhancers(
  applyMiddleware(reduxThunk)
))

请注意,我还添加了
Redux Devtools
,但如果您不想要此附加功能,或者如果没有任何内容可编写,则添加了
applyMiddleware

您的createStore方法是错误的。完成combineReducers函数,然后将中间件作为第三个参数传递给createStore方法。的第二个参数是预加载状态。吸血鬼女仆的解决方案应该能帮到你。