React native Undefined不是一个对象(评估'_react3.default.PropType.shape')?

问题描述 投票:0回答:3

我正在使用react-native build android项目,并使用'Navigator'。当我查看版本时>应使用[email protected]

import { Navigator } from 'react-native-deprecated-custom-components';

App.js

import React, { Component } from 'react';
import {
    Platform,
    StyleSheet,
    Image,
    Text,
    View
} from 'react-native';
import TabNavigator from 'react-native-tab-navigator';
import {
   Navigator
} from 'react-native-deprecated-custom-components';
import PropTypes from 'prop-types';
import Boy from './boy';

const instructions = Platform.select({
   ios: 'Press Cmd+R to reload,\n' +
   'Cmd+D or shake for dev menu',
   android: 'Double tap R on your keyboard to reload,\n' +
   'Shake or press menu button for dev menu',
});

export default class App extends Component {
   constructor(props) {
       super(props)
       this.state = {
          selectedTab: 'tab_polular'
       }
    }
   render() {
       return (
        <View style={styles.container}>
         <Navigator
             initialRoute = {
                 {component: Boy}
             }
             renderScene={(route, navigator) => {
                 let Component = route.component;
                 return <Component navigator={navigator} {...route.params}/>
             }}
        />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
      flex: 1,
      backgroundColor: '#F5FCFF',
  },

得到这个错误:

enter image description here

我看到这个问题类似于我enter link description hereapp.js中添加此代码:

import PropTypes from 'prop-types

但错误也在这里!

如何解决错误!

javascript react-native
3个回答
0
投票

你可以找到关于这个问题here的一些信息,但我会尝试很好地为你收集信息

但基本上,如果你的反应版本> 16,你必须运行npm i --save prop-types然后在你的代码中包括import PropTypes from 'prop-types'

如果您的react版本<16,则必须从React导入PropTypes,就像import React, { Component, PropTypes } from 'react';一样

您可以通过转到项目目录检查您的React版本,打开您的package.json文件,它应该在那里。应该看起来像这样:

"react": "16.0.0-alpha.6",


0
投票
  1. npm install react-native-deprecated-custom-components --save
  2. Navigator.js文件更改为最新版本(来自facebook)

0
投票

好的,我找到错误的原因:

因为反应版本太高了。

我的项目反应版本=== '16.0.0'

react: 16.0.0

如果解决错误,反应版必须是:

"react": "^16.0.0-alpha.12"

然后:

react-native run ios

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.