Javascript React Native Redux createStore错误:undefined不是对象(正在计算“action.type”)

Javascript React Native Redux createStore错误:undefined不是对象(正在计算“action.type”),javascript,react-native,redux,react-redux,Javascript,React Native,Redux,React Redux,我正在使用ReactNative的Redux,我想用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 {

我正在使用ReactNative的Redux,我想用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());
}

创建存储时,您不会调用reducer。createStore接受reducer函数作为其第一个参数

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); // dont call this here, just pass it
}

发送操作的代码在哪里?看起来它是在调度一个空变量而不是actionnice,redux很棒,玩得开心!