diff --git a/completed-apps/infinite-swapi/src/people/InfinitePeople.jsx b/completed-apps/infinite-swapi/src/people/InfinitePeople.jsx index c1caa64f..39af7d11 100644 --- a/completed-apps/infinite-swapi/src/people/InfinitePeople.jsx +++ b/completed-apps/infinite-swapi/src/people/InfinitePeople.jsx @@ -2,7 +2,8 @@ import InfiniteScroll from "react-infinite-scroller"; import { useInfiniteQuery } from "@tanstack/react-query"; import { Person } from "./Person"; -const initialUrl = "https://swapi.dev/api/people/"; +const baseUrl = "https://swapi-node.vercel.app"; +const initialUrl = baseUrl + "/api/people/"; const fetchUrl = async (url) => { const response = await fetch(url); return response.json(); @@ -21,7 +22,7 @@ export function InfinitePeople() { queryKey: ["sw-people"], queryFn: ({ pageParam = initialUrl }) => fetchUrl(pageParam), getNextPageParam: (lastPage) => { - return lastPage.next || undefined; + return lastPage.next ? baseUrl + lastPage.next : undefined; }, }); @@ -48,10 +49,10 @@ export function InfinitePeople() { return pageData.results.map((person) => { return ( ); }); diff --git a/completed-apps/infinite-swapi/src/species/InfiniteSpecies.jsx b/completed-apps/infinite-swapi/src/species/InfiniteSpecies.jsx index 49d5cf28..bf05c774 100644 --- a/completed-apps/infinite-swapi/src/species/InfiniteSpecies.jsx +++ b/completed-apps/infinite-swapi/src/species/InfiniteSpecies.jsx @@ -3,7 +3,8 @@ import { useInfiniteQuery } from "@tanstack/react-query"; import { Species } from "./Species"; -const initialUrl = "https://swapi.dev/api/species/"; +const baseUrl = "https://swapi-node.vercel.app"; +const initialUrl = baseUrl + "/api/species/"; const fetchUrl = async (url) => { const response = await fetch(url); return response.json(); @@ -21,7 +22,9 @@ export function InfiniteSpecies() { } = useInfiniteQuery({ queryKey: ["sw-species"], queryFn: ({ pageParam = initialUrl }) => fetchUrl(pageParam), - getNextPageParam: (lastPage) => lastPage.next || undefined, + getNextPageParam: (lastPage) => { + return lastPage.next ? baseUrl + lastPage.next : undefined; + }, }); if (isLoading) return
Loading...
; @@ -40,10 +43,10 @@ export function InfiniteSpecies() { return pageData.results.map((species) => { return ( ); });