ShrouderS
Reactiflux4y ago
21 replies
Shrouder

✅ – Alforoan – 03-36 Jan 4

if an api link gives me only one page of a collection of movies and i want multiple pages how do i combine the data?
i can get 2nd,3rd, 4th, etc. pages by changing the link at the end to page=(number)
Solution
  const [currentPage, setCurrentPage] = useState(1);

  const FetchMovies = async (page) => {
   const response = await fetch(url+page);
    const movies = await response.json();
    setMovies(prev => [...prev, ...movies.results]);
  };

  React.useEffect(() => {
    FetchMovies(currentPage);
  }, [currentPage]);
Was this page helpful?