[英]Passing textbox value from one file to another
as i am building my first React application in particular react-native application. 因为我正在构建我的第一个React应用程序,特别是react-native应用程序。 I want to pass a textbox value from one js file to another.
我想将文本框值从一个js文件传递到另一个。 Can somebody help me how it should be done?
有人可以帮我怎么做吗?
my code in first.js 我在first.js中的代码
<Text style={{ color: 'black', fontSize: 20, textAlign: 'left', width: width - 60 }}>{GLOBAL.Email}</Text>
<View style={[styles.textInputFrame, { width: width - 48, }]} >
<TextInput
keyboardType='email-address'
style={styles.textInput}
onChangeText={(email) => this.setState({ email })}
returnKeyType='next'
onSubmitEditing={() => this.refs.passwordInput.focus()}
underlineColorAndroid='transparent'
/>
</View>
Thank you in advance 先感谢您
In addition to @khanh solution you can also 除了@khanh解决方案,您还可以
Create your own data store which you will import in your different files to store your data. 创建自己的数据存储,将其导入到其他文件中以存储数据。 I highly recommend using the observer pattern for this one (see https://www.dofactory.com/javascript/observer-design-pattern ).
我强烈建议为此使用观察者模式(请参阅https://www.dofactory.com/javascript/observer-design-pattern )。
Send a event on which you can subscribe anywhere in your app, you can use https://www.npmjs.com/package/react-native-event-listeners for this one. 发送一个可以在应用程序中任何位置订阅的事件,您可以为此使用https://www.npmjs.com/package/react-native-event-listeners 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.