Javascript React native Undefined不是对象(正在计算“U react3.default.PropType.shape”)
我正在学习React native,因为这个案例我想为IOS和Android创建导航,实际上,我遇到了一个错误 错误:React native Undefined不是一个objectevaluating''u react3.default.PropType.shape' 我的开发环境 操作系统:MACOS Sierra Clie:react本机cli:2.0.1 反应本机版本:反应本机:0.49.3 我遵从官方的反应 App.jsJavascript React native Undefined不是对象(正在计算“U react3.default.PropType.shape”),javascript,android,ios,facebook,react-native,Javascript,Android,Ios,Facebook,React Native,我正在学习React native,因为这个案例我想为IOS和Android创建导航,实际上,我遇到了一个错误 错误:React native Undefined不是一个objectevaluating''u react3.default.PropType.shape' 我的开发环境 操作系统:MACOS Sierra Clie:react本机cli:2.0.1 反应本机版本:反应本机:0.49.3 我遵从官方的反应 App.js import React, { Component } from
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位于名为propTypes的新包中
请参阅:react:16.0.0-beta.5,执行'npm i-保存道具类型',然后在您的组件中从'prop-types'导入道具类型,我遇到了相同的问题,我也尝试过这样做,但问题仍然存在。我在文件中插入了导入行:NavigatorBreadcrumbNavigationBar.js,我错过了什么吗?@ROI我在这里遇到了与NavigatorBreadcrumbNavigationBar.js相同的问题。你有没有想过这个问题?这里也有同样的问题。我安装了道具类型。如果我制作了一个test.js文件并需要“prop-types”,它就会找到它。但在ios和android上运行时,NavigatorReadCrumbNavigationBar.jsPropTypes在最新版本中已从react中删除,这给了我这个错误。所以你需要使用和其他软件包。reactjs和react native之间有区别吗?是的,有区别。但是react native依赖于react js。相同的用法只是一些UI组件的不同而已。例及