ReferenceError:找不到变量
问题描述:
所以我是新来的React本地,但每次我把一个新的组件像一个按钮或来自Facebook的图像React Native Doc的我不断收到“ReferenceError:找不到变量”模拟器上出现错误?当我添加文本以外的任何其他代码时,这真的会发生。我没有错误地链接一些东西吗?任何事情都会有帮助。ReferenceError:找不到变量
/**
* 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,
},
});
**错误 This is the error
答
尝试增加Button
的进口,像这样:
import {
Platform,
StyleSheet,
Text,
View,
Button
} from 'react-native';
+0
哈哈我也注意到了 –
+1
这就是尴尬:) – Mirakolous
文字和画面,从反应本地的,为什么进口不是招” t Button是否从任何地方导入? – castis
对不起,我的无知,但每个组件都必须列在进口清单下? –
不用担心,是的,您想在给定文件中使用的所有内容都需要从其他地方导入,或者在使用之前以某种方式声明。 – castis