5
我想創建一個文本輸入元素,但它始終拋出錯誤說「無法找到變量:TextInput」,即使我從他們的入門頁面複製代碼。React Native - 無法創建文本輸入
代碼:
/**
* Sample React Native App
* https://github.com/facebook/react-native
*/
'use strict';
var React = require('react-native');
var {
AppRegistry,
StyleSheet,
Text,
View,
} = React;
var AwesomeProject = React.createClass({
render: function() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
My App Name
</Text>
<TextInput
style={{height: 40, borderColor: 'gray', borderWidth: 1}}
onChangeText={(text) => this.setState({input: text})}
/>
<Text>{'user input: ' + this.state.input}</Text>
</View>
);
}
});
var styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
AppRegistry.registerComponent('AwesomeProject',() => AwesomeProject);
和錯誤的連接的圖像。
只需添加到這一點:如果你忘了在另一個文件中導入的TextInput(比如AnotherThing.js )被導入到App.js中時,該錯誤看起來像是來自App.js,即使它來自AnotherThing.js – nemicolopterus