【发布时间】:2018-03-08 13:51:18
【问题描述】:
TypeError 是从 JoinNavigator 开始的。
export class JoinNavigator extends React.Component {
render() {
return (
<JoinStackNavigator
onNavigationStateChange={(prevState, currentState) => {
this._getCurrentRouteName(currentState)
}}
/>
);
}
_getCurrentRouteName(navState) {
if (navState.hasOwnProperty('index')) {
this._getCurrentRouteName(navState.routes[navState.index])
} else {
console.log("Current Route Name:", navState.routeName);
let regExp = /^AskStep/;
if(navState.routeName.match(regExp)){
this.props._changeVisibleStatusBar(); //It's located at this.
}
}
}
}
const mapStateToProps = ({app}) => {
return app;
};
const mapDispatchToProps = dispatch => {
return {
_changeVisibleStatusBar: () => {
dispatch(changeVisibleStatusBar(false))
}
};
};
export default connect(mapStateToProps, mapDispatchToProps)(JoinNavigator);
行动。
当我在 JoinNavigator 调用该操作时,它是有效的。没问题。
import {
APP_STATUS_BAR
} from './types'
export const changeVisibleStatusBar = (val) => {
return {
type: APP_STATUS_BAR,
payload: {hiddenStatusBar: val}
}
};
减速器。
您可以看到“console.log”。
其作品。
所有数据参数在 React Native Debugger 上显示良好。
import {
APP_STATUS_BAR
} from '../actions/types';
const INITIAL_STATE = {
hiddenStatusBar: false,
isFetching: false,
error: false
};
export default (state = INITIAL_STATE, action) => {
switch (action.type) {
case APP_STATUS_BAR:
console.log(action); //It's works well.
return {
...state,
...action.payload
};
default:
return state;
}
};
显然, - 从 JoinNavigator 调用操作。 - 它通过 Action 发送并传递给 Reducer。 (我看到了console.log)
那么...为什么是 TypeError?
TypeError: TypeError: Cannot read property 'type' of undefined
This error is located at:
in NavigationContainer (at JoinNavigator.js:60)
in JoinNavigator (created by Connect(JoinNavigator))
in Connect(JoinNavigator) (at SceneView.js:17)
in SceneView (at CardStack.js:385)
in RCTView (at View.js:71)
.....
需要帮助。
谢谢。
【问题讨论】:
-
欢迎来到
React-Native! -
@triandicAnt 嗨 triandicAnt :) 我对 React-Native 感觉很好,但其他事情不同。 (如安卓、jQuery)
标签: react-native redux typeerror