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

120
Visualizações
Trying to get fetched API data into Return code - React.js

Let me start with my code, and then will describe my problem:

  function ArrayList6(props) {
  const title = "Results";

  let parseArray = [];

  const thisFunc = async () => {
    const parseTest = new Parse.Query("Users");
    parseTest.equalTo("LastName", "Jenkins");
    let queryResults = await parseTest.find();

    for (const item of queryResults) {
        parseArray.push(item.get('LastName'))
    }

    console.log("data in function: " + parseArray) 
  };

  thisFunc();
    
  return (
    <div className="App">
      <NavBar title={title} />
      <ul className="no-bullets">
        {parseArray.map((item) => (
          <li key={item}>{item}</li>
        ))}
      </ul>
    </div>
  );
}

export default ArrayList6;

In short, the problem is that when I fetch my API data Asynchronously, the code keeps running and hits the return portion before the API has fetched the needed data - this is a problem because the returned portions depends on the fetched API data.

If you run the code, you can see that the console displays the fetched data, but the main component does not return it.

I'd be happy to set the API fetch so it's not async, and then the rest of the code waits until it's complete, but I haven't figured out how to do that. If someone who is wiser and smarter than I am, I would greatly appreciate it.

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