Search code examples
react-nativeasyncstorage

pass value from asyncstorage to another page


I am a total newbie in this programming world so forgive my foolishness. I wanna know is it possible if I store a data in asyncstorage in login page and pass it to another page?

Btw this is how I save the data into asyncstorage in login page:

 componentWillReceiveProps(nextProps){
    if(nextProps.isLoginSuccess){
      this.props.navigation.navigate('logged');
      AsyncStorage.setItem('Login_token', this.state.username);
    }    
  }  

If I want to pass the username to another page, how do I do it?


Solution

  • You set the username, now you can get it from any page:

    AsyncStorage.getItem('Login_token')
      .then((token) => { 
        console.log(token);
      });