gpt4 book ai didi

react-native - 如何在 React Native 中将数据从一个屏幕传递到另一个屏幕

转载 作者:行者123 更新时间:2023-12-04 03:59:53 25 4
gpt4 key购买 nike

1. index.android.js

import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
TextInput,
View
} from 'react-native';

import Button from 'react-native-button';

class AwesomeProject extends Component {

constructor(props){
super(props)

this.state = {
username: '',
email: '',
address: '',
mobileNumber: ''
}


render() {
return (
<View style={styles.container}>

<TextInput
ref={component => this.txt_input_name = component}
style={styles.textInputStyle}
placeholder="Enter Name"
returnKeyLabel = {"next"}
onChangeText={(text) => this.setState({username:text})}
/>

<Button style={styles.buttonStyle}>
Submit
</Button>
</View>
);
}
}

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
buttonStyle: {
alignSelf: 'center',
textAlign: 'center',
color: '#FFFFFF',
fontSize:18,
marginTop:20,
marginBottom:20,
padding:5,
borderRadius:5,
borderWidth:2,
width:100,
alignItems: 'center',
backgroundColor:'#4285F4',
borderColor:'#000000'
}
});

AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject);

最佳答案

您需要使用导航器将 Prop 传递到另一个页面

 this.props.navigator.push({
name: 'Home',
passProps: {
name: property
}
})

我从这个链接中获取了这个 https://medium.com/@dabit3/react-native-navigator-navigating-like-a-pro-in-react-native-3cb1b6dc1e30#.6yrqn523n

关于react-native - 如何在 React Native 中将数据从一个屏幕传递到另一个屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39721381/

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