【发布时间】:2018-08-06 21:49:10
【问题描述】:
我正在开发一个 CRNA 应用程序,但是,商店连接不起作用,我在创建商店时收到上述错误。
“未定义不是对象(评估action.type)
搜索类似问题,我找到了this question,这是一个在传递给createStore 函数时被调用的reducer,这不是我的情况。
还有this one,它与在异步调度程序之前调用的AnalyticsTracker 相关,这也不是我的情况。
这是重现的最少代码。
App.js
import React from 'react';
import {
View,
Text
} from 'react-native';
import { Provider } from 'react-redux';
import store from './store';
class App extends React.Component {
render() {
return (
<Provider store={store}>
<View>
<Text>Hello</Text>
</View>
</Provider>
);
}
}
store.js
import { createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import reducer from './reducer';
// Here the error happens
export default createStore(reducer, applyMiddleware(thunk));
reducer.js
import actionTypes from './action_types';
const initialState = {
}
export default (action, state=initialState) => {
// This is the top line on stacktrace
switch (action.type) {
case actionTypes.MY_ACTION:
return state;
}
return state;
}
我已尝试对我的代码进行一些更改,即:删除中间件。
知道为什么会这样吗?我错过了什么吗?
【问题讨论】:
-
如果你去掉你的开关盒,是不是去掉了错误?
标签: ios react-native react-redux create-react-native-app