【发布时间】:2017-09-16 12:09:31
【问题描述】:
我正在使用 Redux 和 ReactNative,我想用 reducer 创建一个商店
并且,我在下面遇到错误,指向 reducer.js 中函数 switchToTab() 中的“switch (action.type)”行
undefined is not an object(evaluating 'action.type')
这是我的actions.js
export const SWITCH_TAB = 'switchTab'
export function switchTab(index) {
return {
type: SWITCH_TAB,
index: index
}
}
这是我的 reducer.js
import { SWITCH_TAB } from './actions.js'
export function switchToTab(state = {}, action) {
switch (action.type) {//error point to this line
case SWITCH_TAB:
return Object.assign({}, ...state, {
index: action.index
});
break;
default:
return state;
}
}
这里是createStore:
import { createStore } from 'redux';
import { switchToTab } from './reducer.js'
export default class MainPage extends Component {
constructor(props) {
super(props);
this.state = {
index:0
};
let store = createStore(switchToTab());
}
【问题讨论】:
-
分派动作的代码在哪里?看起来它正在调度一个空变量而不是一个动作
标签: javascript react-native redux react-redux