问题描述
我使用 mern 堆栈设计了一个 CRM 工具,当我尝试从 mongoDB 检索与项目阶段相关的特定信息时,我看到了以下错误:
getStages api error:
TypeError: action.payload is not iterable
at stageReducer (stageReducers.js:11)
at combination (redux.js:528)
at computeNextEntry (<anonymous>:3395:21)
at recomputeStates (<anonymous>:3429:17)
at <anonymous>:3809:22
at Object.dispatch (redux.js:288)
at dispatch (<anonymous>:3856:17)
at index.js:11
at dispatch (redux.js:659)
at stageAction.js:7
另外,我在这个实现中使用了 redux。我实现了这个功能的后端并用邮递员测试它并且它完美地工作 但前端没有按预期检索信息。 stageReducer、stageAction 和 index.js 文件如下:
stageReducer:
import { GET_STAGES } from "../constants/stageConstants";
const INITIAL_STATE = {
stages: []
};
const stageReducer = (state=INITIAL_STATE,action) => {
switch(action.type){
case GET_STAGES:
return{
stages: [...action.payload]
};
default:
return state;
}
};
export default stageReducer;
舞台动作:
import { GET_STAGES } from "../constants/stageConstants";
import axios from "axios";
export const getStages = () => async dispatch =>{
try{
const response = await axios.get('/stages');
dispatch({
type: GET_STAGES,payload: response.data.stages
});
console.log(response);
}catch(err){
console.log('getStages api error:',err);
}
}
index.js
import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./components/App";
import reportWebVitals from "./reportWebVitals";
import { Provider } from 'react-redux';
import store from './redux/store';
ReactDOM.render(
<React.StrictMode>
<Provider store ={store}>
<App/>
</Provider>
</React.StrictMode>,document.getElementById("root")
);
reportWebVitals();
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)