【发布时间】:2018-05-12 18:06:46
【问题描述】:
我的 Redux 提取返回空.. 它不会中断,但只会返回空对象。
这是我的操作 (newsActions.js) 的代码:
import axios from 'axios';
import kickstarterData from '../server/kickstarter-october.json';
export const FETCH_KICKSTARTER = 'FETCH_KICKSTARTER';
export function fetchKickstarter() {
return {
type: FETCH_KICKSTARTER,
payload: {
data: kickstarterData
}
};
}
这是我的减速器:
import { FETCH_KICKSTARTER } from '../actions/kickstarterActions';
export default function(state = [], action) {
switch (action.type) {
case FETCH_KICKSTARTER:
debugger;
return [action.payload.data, ...state];
}
return state;
};
https://stackoverflow.com/questions/ask#
这是我的 index.js,它结合了所有的 reducer:
import { combineReducers } from 'redux';
import NewsReducer from './reducer_news';
import KickstarterReducer from './reducer_kickstarter';
const rootReducer = combineReducers({
news: NewsReducer,
kickstarters: KickstarterReducer
});
export default rootReducer;
最后,在我的 app.js 中,我有以下代码:
const mapStateToProps = (state) => ({
news: state.news,
kickstarters: state.kickstarters
});
export default connect(mapStateToProps, {...newsActions, ...kickstarterActions})(App);
谁能告诉我为什么会这样? 另外,任何人都可以建议我编写这些代码的更好/更清洁的方式吗?
谢谢
【问题讨论】:
标签: javascript reactjs redux react-redux redux-thunk