React Native Redux createStore error:undefined is not an object(evaluating 'action.type')
React Native Redux createStore error:undefined is not an object(evaluating 'action.type')
我正在使用 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());
}
创建商店时不调用减速器。 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
}
我正在使用 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());
}
创建商店时不调用减速器。 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
}