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

203
Visualizações
Run API requests sequentially in react native?

Looking for the best way to accomplish the following.

The goal is to, when this screen loads:

  1. Retrieve the user's auth token from async storage, THEN
  2. Hit an API with the auth token to grab some user details (in this case userId)

I'm also trying to useEffect so these only run once.

Function 1:

const getUserToken = async () => {
      try {
        const userToken = await AsyncStorage.getItem("userToken", userToken);
        setUserToken(userToken);
      } catch (err) {
        console.log("err retrieving token " + err);
      }

Function 2:

const getUserId = async () => {
      try {
        let response = await xano.get("/auth/me", {
          headers: { Authorization: userToken },
        });
        setUserId(response.data.id);
        console.log(userId);
      } catch (err) {
        console.log("getUserId err " + err);
        console.log(err.data);
      }
    };

Function 3:

 useEffect(() => {
    getUserToken();
getUserId();

  }, []);
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You need to await those async functions in the useEffect hook.

useEffect(() => {
    async function fetchMyAPI() {
      await getUserToken();
      await getUserId();      
    }
    fetchMyAPI();
}, [])  
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