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

280
Visualizações
React Native - Call Async Function From Another Component To Store and Get Data

I'm trying to call an async function to store and get data that I fetch from an API. The user is supposed to get a token on the login screen, and the token will be shown on the home screen. But the token is not shown in the console when the user presses the button on the home screen link.js

export const SET_USER_AUTH = async ({accessToken, tokenType, expiresAt}) => {
    try {
        await AsyncStorage.setItem('@access_token', accessToken);
        await AsyncStorage.setItem('@token_type', tokenType);
        await AsyncStorage.setItem('@expires_at', expiresAt);
        await AsyncStorage.setItem('@user_auth', tokenType + " " + accessToken);
        console.log("Done SET_USER_AUTH");
    } catch(e) {
    // read error
    }
};

export const GET_USER_AUTH = async () => {
    try {
        const accessToken = await AsyncStorage.getItem('@access_token');
        const tokenType = await AsyncStorage.getItem('@token_type');
        const expiresAt = await AsyncStorage.getItem('@expires_at');
        const userVer = await AsyncStorage.getItem('@user_auth');
        console.log("Done GET_USER_AUTH");
    } catch(e) {
    // read error
    }
};
    

Home.js

return (
        <Button onPress={() => console.log(GET_USER_AUTH.userVer)}/>
    );
about 4 years ago · Juan Pablo Isaza
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