Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

173
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!