javascript - React Native Undefined 不是一个对象(正在评估'_react3.default.PropType.shape')

标签 javascript android ios facebook react-native

我正在使用React-native学习,因为这种情况我想为IOS和Android创建导航,实际上,我遇到了错误

错误:React Native Undefined不是一个对象(正在评估'_react3.default.PropType.shape')

我的开发环境

  • 操作系统:MACOS Sierra
  • Clie:react-native-cli:2.0.1
  • React-native 版本:react-native:0.49.3

我关注的是官方的react-native tutorial

App.js

import React, { Component } from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';
import Navigator from 'react-native-deprecated-custom-components';
import MyScene from './src/components/navigation/MyScene';



const instructions = Platform.select({
  ios: 'IOS: Press Cmd+R to reload,\n' +
    'Cmd+D or shake for dev menu',
  android: 'Android : Double tap R on your keyboard to reload,\n' +
    'Shake or press menu button for dev menu',
});
export default class App extends Component {
    render() {
        return (

            <Navigator initialRoute={{ title: 'My Initial Scene', index: 0 }}
                renderScene={(route, navigator) =>
                    <MyScene
                        title={route.title}

                        // Function to call when a new scene should be displayed
                        onForward={() => {

                            const nextIndex = route.index + 1;
                            navigator.push({
                                title: 'Scene ' + nextIndex,
                                index: nextIndex,
                            });
                        }}

                        // Function to call to go back to the previous scene
                        onBack={() => {
                            if (route.index > 0) {
                                navigator.pop();
                            }
                        }}
                    />
                }
            />
        )
    }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 50,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

MyScene.js

import React, { Component, PropTypes } from 'react';
import { View, Text, TouchableHighlight } from 'react-native';

export default class MyScene extends Component {
    render() {
        return (
            <View>
                <Text>Current Scene: {this.props.title}</Text>
                <TouchableHighlight onPress={this.props.onForward}>
                    <Text>Tap me to load the next scene</Text>
                </TouchableHighlight>

                <TouchableHighlight onPress={this.props.onBack}>
                    <Text>Tap me to go back</Text>
                </TouchableHighlight>
            </View>
        )
    }
}

MyScene.propTypes = {
    title: PropTypes.string.isRequired,
    onForward: PropTypes.func.isRequired,
    onBack: PropTypes.func.isRequired,
};

最佳答案

检查您的 React 版本, 如果版本 > 16,则 propTypes 位于名为 prop-types

的新包内

参见:https://www.npmjs.com/package/prop-types

关于javascript - React Native Undefined 不是一个对象(正在评估'_react3.default.PropType.shape'),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46781664/

相关文章:

android - Glide : How to find if the image is already cached and use the cached version?

ios - iPhone 和 Mac 之间的通信

ios - 多次调用 UITableViewCell 中的禁用/启用 UIButton

javascript - Tailwind 全局使用本地文件中的字体

javascript - 找不到变量 : DS in Ember CLI

javascript - 使用稍后确定的参数调用 JavaScript 函数

android - 无法使用 MediaBrowserServiceCompat

javascript - jQuery/Javascript : scrollTop Value in all browsers?

android - 以编程方式将小部件添加到android中的主屏幕

ios - UITableViewCells 之间的间距