Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

183
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda