未定义不是对象(正在评估'_this.props.navigation.state.index')

时间:2018-11-01 01:43:24

标签: javascript react-native react-redux

我正在尝试使用this样板并通过this教程来学习RN。我使用react-native-cli设置了这个项目,而在本教程中是通过expo完成的。我写了完全相同的代码,但是,我不知道它从哪里中断。我想知道是否它必须与react-native版本做些事情,我的应用程序运行在0.57.4上,而在教程中它是低于版本的:

{
 "react-native": "https://github.com/expo/react-native/archive/sdk-19.0.0.tar.gz"
}

我尝试在RN 0.52上运行该应用程序,但没有成功,我不知道此sdk链接的实际RN版本是什么,所以我可以尝试一下,有人可以建议,谢谢!!

App.js

import React from 'react';
import { UIManager } from 'react-native';
import { ApolloProvider } from 'react-apollo';
import { ThemeProvider } from 'styled-components';

import { store, client } from './src/store';
import { colors } from './src/utils/constants';

import Welcome from './src/components/Welcome';
import HomeScreen from './src/screens/HomeScreen';
import AppNavigation from './src/navigations';

if (UIManager.setLayoutAnimationEnabledExperimental) {
  UIManager.setLayoutAnimationEnabledExperimental(true);
}

export default class App extends React.Component {
  render() {
    return (
      <ApolloProvider store={store} client={client}>
        <ThemeProvider theme={colors}>
         <AppNavigation />
        </ThemeProvider>
      </ApolloProvider>
    );
  }
}

navigations.js

import React, { Component } from 'react';
import { addNavigationHelpers, StackNavigator, TabNavigator } from 'react-navigation';
import { connect } from 'react-redux';

import HomeScreen from './screens/HomeScreen';

const AppMainNav = StackNavigator({
  Home: {
    screen: HomeScreen
  }
});

class AppNavigator extends Component {
  render() {
    const nav = addNavigationHelpers({
      dispatch: this.props.dispatch,
      nav: this.props.nav
    })
    return <AppMainNav navigation={nav} />;
  }
}

export default connect(state => ({
  nav: state.nav
}))(AppNavigator);

export const router = AppMainNav.router;

navigation.js

import { router } from '../navigations';



export default (state, action) => {
  const newState = router.getStateForAction(action, state);
  return newState || state;
}

0 个答案:

没有答案