gpt4 book ai didi

javascript - reducer 不是函数

转载 作者:行者123 更新时间:2023-11-30 15:34:25 26 4
gpt4 key购买 nike

尝试创建 reducers 并从 action 中获取数据

但是在控制台报错:reducer is not a function.....

我的 reducer :

import { INCOME_LIST } from '../actionTypes'

import Immutable from 'immutable'

const initialUserState = {
list: []
}

const listReducer = function(state = initialUserState, action) {
switch(action.type) {
case 'INCOME_LIST':
return Object.assign({}, state, { list: action.data });
}
return state;
}

我哪里错了?

我的行动:

import axios from 'axios'
import { INCOME_LIST } from '../actionTypes'



function receiveData(json) {
return{
type: INCOME_LIST,
data: json
}
};


export function IncomeList () {

return dispatch => {

return (

axios.post('http://139.196.141.166:8084/course/income/outline',{}, {
headers: { 'X-Authenticated-Userid': '15000500000@1' }
}).then(function (response) {

dispatch(receiveData(response.data));

})

)
}
}

如何正确地为此创建 reducer ?

最佳答案

看起来您从未导出过 reducer 。 listReducer.js 文件中的 export default listReducer 应该可以解决问题。

关于javascript - reducer 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41792169/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com