react-native – 如何将数据从一个屏幕传递到React Native中的其他屏幕

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

最佳答案 您需要使用导航器将道具传递到另一个页面

 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

点赞