Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

151
Visualizações
Put data from AsyncStorage in Text

I've stored my data in local host using AsyncStorage and it's work fine. I'm able to alert and offline login, but when i go to another page I can do alert but I can't put it in Text. I tried some ways but it didnt work.

onSumbit = async () => {
  try{
    await AsyncStorage.setItem('UserEmail',this.state.UserEmail)
  }catch (err){
    console.log(err)
  }
}

getData = async () => {
  try {
    const UserEmail = await AsyncStorage.getItem('UserEmail')
    if(UserEmail !== null) {
      this.setState({ UserEmail });
      console.log(UserEmail);
    }
  } catch(e) {
    //Error reading value
  }
}

<Text style={styles.FormText}>{this.state.UserEmail}</Text>
<TextInput
  placeholder="Enter User Email"
  value={this.state.UserEmail}
  onChangeText={(UserEmail) => this.setState({UserEmail})}
  underlineColorAndroid='transparent'
  style={styles.TextInputStyleClass} />
  //This code is working

displayData = async ()=> {
  try{  
    let user = await AsyncStorage.getItem('UserEmail');  
    alert(user);
  }catch(error){
    alert(error)  
  }  
}



/// in home page (another page )
render() {
  return (  
    <TouchableOpacity onPress ={this.displayData}>  
    <Text>Click to display data</Text>  
    </TouchableOpacity> 
  );
}    
//This is work too, but in the Text it's not working
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use JSON.parse() to convert AsyncStorage data String to JSON format

This is your code:

let user = await AsyncStorage.getItem('UserEmail');  
alert(user);

And this is what you need to do:

let user = await AsyncStorage.getItem('UserEmail');  
alert(JSON.parse(user));
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda