Where do we get this data from?
We will use TanStack Query in this course
Configure TanStack Query
npm i @tanstack/react-query
Using Tanstack Query for data fetching
Clean & simple – also comes with retry, cache & more functionality
Since we are using TypeScript, we should always work with defined types — avoid any !
export async function fetcher<T>(uri: string): Promise<T> {
const response = await fetch(uri);
if (!response.ok) throw new Error('Could not fetch data!');
return response.json();
};
https://pokeapi.co/api/v2/pokemon?limit=5
https://pokeapi.co/api/v2/pokemon/bulbasaur/
ListPage.tsx
DetailPage.tsx
Why doesnt useQuery fit?
Note how there is no query key and no data.
We learned…