2017-01-12 3 views
1

2ページ間のリロードデータが、私のメインページのリロードデータ私のアプリの再起動が、私の2ページ目の印刷と保存私のデータはすぐに私は私のアプリでは2ページの間でデータを渡したい

これは私の第二の場合のみページ

import React, { Component } from 'react'; 
    import { 
    TouchableHighlight, 
    TouchableOpacity, 
    AsyncStorage, 
    AppRegistry, 
    StyleSheet, 
    Navigator, 
    TextInput, 
    ListView, 
    onPress, 
    Button, 
Image, 
Text, 
View, 
    } from 'react-native'; 


var styles = require('../style.js'); 

var count; 


class config extends React.Component { 
constructor(props) { 
super(props); 
this.state = { local: '', 
       ext: '', 
       }; 
} 

componentWillMount() { 
    AsyncStorage.getItem("local").then((value) => { 
     this.setState({"local": value}); 
    }).done(); 
    AsyncStorage.getItem("ext").then((value) => { 
     this.setState({"ext": value}); 
    }).done(); 
} 

    saveData(target, value, i) { 
    if (i === 1){ 
    AsyncStorage.setItem("local", value); 
    this.setState({local: value}); 
    } 
    else{ 
     AsyncStorage.setItem("ext", value); 
     this.setState({ext: value}); 
    } 
} 


render(){ 
return(

    <View> 

    <View style={styles.container}> 
    <Image source={require('../../img/mob.png')} style={styles.mob_logo}/> 
    </View> 

    <View style={{marginTop:100}}> 
     <Text style={{fontSize:20}}>Hello From config component</Text> 
     <Text>id: {this.props.id}</Text> 
     <Text>name: {this.props.name}</Text> 
     <Text>name: {this.props.myVar}</Text> 
     <Text style={styles.saved}> 
      {this.state.local} 
     </Text> 
     <Text> </Text> 
     <TextInput 
     style={{height: 40, borderColor: 'gray', borderWidth: 1}} 
     onChangeText={(local) => this.saveData("local",local,1)} 
     value={(local) => this.saveData("local",local,1)} 
     /> 

     <Text style={styles.saved}> 
      {this.state.ext} 
     </Text> 
     <TextInput 
     style={{height: 40, borderColor: 'gray', borderWidth: 1}} 
     onChangeText={(ext) => this.saveData("ext",ext,2)} 
     value={(ext) => this.saveData("ext",ext,2)} 
     /> 
    </View> 
    </View> 
) 
} 
} 

    module.exports = config; 

私はローカルとextを私の1erページに渡したいと思いますか?

答えて

0

2ページに親子関係がない場合は、フラックスアーキテクチャを使用してコンポーネント間でデータを共有します。

React-Redux

関連する問題