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

174
Visualizações
useEffect, useState and promises.. what to do

I'm having trouble at the moment of getting these values. First, I have a token that I have to retrieve via SecureStore, for these I do it with useState, then I have an async function called getData(id), this id is used to query an API. I have to do 3 of these calls to 3 diferent id's, the data I get from the API I passed it to state hook called qo.

I use the useEffect hook for the first render to get the token, after that the second useEffect, that reacts to the token state, I call the getData funcion, but when it renders, it only shows 1 result of the other.

Code

const [st, onSt] = useState("");
const [qo, onQo] = useState([]);

const getValue = async() => {
  let result = await SecureStore.getItemAsync("ST");
  if (result) {
    onSt(result);
  }
};

const getData = async(id) => {
  return fetch(`https: //URL.COM/api/card/${id}`, {
      method: "GET"
    })
    .then((ans) => ans.json())
    .then((json) => {
      const obje = json.result_metadata[0].fingerprint.type;
      const tip = obje["type/Number"];
      onQo([
        ...qo,
        {
          title: json.name,
          value: tipo.max,
          author: json.creator.common_name,
        },
      ]);
    })
    .catch((error) => console.log(error));
};

useEffect(() => {
  getValue();
}, []);

useEffect(() => {
  getUser();
  getData(2272);
  getData(2273);
  getData(2274);
}, [st]);

I tried different useState but it is not a good solution

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