所以我是React Native的新手,但是每次我放置一个像Button一样的新组件或来自Facebook的图像时React Native Doc我在模拟器上不断收到“ReferenceError:找不到变量”错误?当我添加除Text之外的任何其他代码时,诚实地发生这种情况。我没有错误地链接什么?任何事都会有所帮助。
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
View
} from 'react-native';
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<{}> {
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
This is a new App!
</Text>
<Text style={styles.instructions}>
To get started, edit App.js
</Text>
<Text style={styles.instructions}>
{instructions}
</Text>
<Button
onPress={onPressLearnMore}
title="Learn More"
color="#841584"
accessibilityLabel="Learn more about this purple button"
/>
<Text style={{color: 'blue'}}>Hello</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'white',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
** ERROR This is the error
答案 0 :(得分:3)
尝试将Button
添加到导入中,如下所示:
import {
Platform,
StyleSheet,
Text,
View,
Button
} from 'react-native';