gpt4 book ai didi

reactjs - React Native - 无法创建文本输入

转载 作者:行者123 更新时间:2023-12-03 13:25:23 24 4
gpt4 key购买 nike

我正在尝试创建一个文本输入元素,但它不断抛出错误,提示“找不到变量:TextInput”,即使我从他们的入门页面复制了代码。

代码:

/**
* 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);

并附有错误图像。 enter image description here

最佳答案

您需要使用其余的react-native组件初始化TextInput,如下所示:

var {
TextInput,
AppRegistry,
StyleSheet,
Text,
View,
} = React;

关于reactjs - React Native - 无法创建文本输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31193782/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com