Home asyncStorage reload after update on all page
Reply: 0

asyncStorage reload after update on all page

Shinix
1#
Shinix Published in 2017-12-07 17:48:44Z

Sorry i'm beginner with react-native and Async, i do not find correct answer...

I have 2 pages Params.js and Index.js

Here is short code for Params.js

   constructor(props) {
    super(props);
    this.state = {
        surname: '' 
    }
  }
componentWillMount() { 
    AsyncStorage.getItem("surname").then((value) => {
        this.setState({"surname": value});
    }).done();
}
setData() {
    try {
        AsyncStorage.setItem("surname", this.state.surname);
    } catch (error) {
      console.log(error)
    }
}
render () {  
        return (
            <Input onChangeText={(text) => { 
                this.setState({surname: text }) }} value={this.state.surname} 
            />                         
            <Button transparent onPress={() => this.setData()} ><Text>SAVE</Text></Button>
        )
 }

I can with this previous code save and store data but if i come back on the index page the data is not updated

I find data with this code on index.js :

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

Why my state "surname" isn't updated ?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.323688 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO