【问题标题】:Why is it TypeError in React-Native?为什么 React-Native 会出现 TypeError?
【发布时间】: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


【解决方案1】:

尝试在 chrome 或 Firefox 中安装 redux 开发工具,以检查触发了哪些操作。一些未定义的动作正在被调度,但很难知道从哪里来

【讨论】:

    猜你喜欢
    • 2018-07-07
    • 1970-01-01
    • 2020-05-13
    • 1970-01-01
    • 2021-12-11
    • 2013-06-14
    • 2018-11-10
    • 1970-01-01
    • 2019-12-21
    相关资源
    最近更新 更多