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
Swapi Star Wars API Only Renders 10 Planets When Called

Note: I'm very new when it comes to rendering APIs.

Recently, I was assigned homework for calling and rendering API data from any API of our choosing. I chose the Swapi Star Wars API do it its high popularity. After choosing my API of choice, I was assigned to call and display all 60 planets within the Star Wars API. After wrestling with the API for the last two days, my calls to the API displayed only 10 sets of data. I've kept trying to utilize the useEffect and useCallback hooks for clean up purposes along with along with utilizing different conditions in order to set up and terminate a loop to get all sets of data but yet to no avail, I couldn't get the rest of the data to render. After utilizing Postman to display the data from the API call, I can't seem to find a definitive solution to display all 60 planets within the Swapi Star Wars API. Would be really appreciated if anyone can help me. Cheers.

Here is my code:

import React, {useEffect, useState} from 'react';

function App() {
  const [planets, setPlanets] = useState([]);
  const [url, setURL] = useState(`https://swapi.dev/api/planets/`);

  useEffect(() => {
    async function fetchPlanets(){
      let res = await fetch(url);
      let data = await res.json();
      do{
        setPlanets(data.results);
        setURL(data.next);
      } while(data.next !== null)
    }
      fetchPlanets();
  },[planets, url]);

  return (
    <div className="App">
      {planets && planets.map((planet,i) => {
        return(
          <h1 key={i}>
            {planet.name}
          </h1>
        );
      })}
    </div>
  );
}

export default App;
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