我使用终极版与ReactNative,我想创建一个存储与减速器阵营本地终极版createStore错误:未定义不是对象(计算“action.type”)
而且,我得到了以下错误,点到线在reducer.js在功能switchToTab( '开关(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());
}
调度动作的代码在哪里?看起来它是调度一个空变量而不是一个动作 –