我正在尝试制作一个带有触发操作的按钮的简单 iOS 页面。我已按照有关如何入门的教程进行操作,这是我的索引代码:
'use strict';
var React = require('react-native');
var {
AppRegistry,
StyleSheet,
Text,
View,
TouchableHighlight,
Component,
AlertIOS // Thanks Kent!
} = React;
class myProj extends Component {
render() {
return (
<View style={styles.container}>
<Text>
Welcome to React Native!
</Text>
<TouchableHighlight style={styles.button}
onPress={this.showAlert}>
<Text style={styles.buttonText}>Go</Text>
</TouchableHighlight>
</View>
);
}
showAlert() {
AlertIOS.alert('Awesome Alert', 'This is my first React Native alert.', [{text: 'Thanks'}] )
}
}
var styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#FFFFFF'
},
buttonText: {
fontSize: 18,
color: 'white',
alignSelf: 'center'
},
button: {
height: 44,
flexDirection: 'row',
backgroundColor: '#48BBEC',
alignSelf: 'stretch',
justifyContent: 'center'
}
});
AppRegistry.registerComponent('myProj', () => myProj);
问题是,当我在我的设备上从 Xcode 运行它时,我得到
Can't find variable: React
render
main.jsbundle:1509:6
mountComponent
mountChildren
知道这里可能是什么问题吗?
原文由 KeykoYume 发布,翻译遵循 CC BY-SA 4.0 许可协议
在最新版本的 React Native 中,您必须从“react”包中导入 React