2026-02-05 15:09:14 +01:00
|
|
|
import { useQuery } from '@tanstack/react-query'
|
2026-02-14 16:41:24 +01:00
|
|
|
import {
|
|
|
|
|
getPokemon,
|
|
|
|
|
fetchPokemonFamilies,
|
|
|
|
|
fetchPokemonEncounterLocations,
|
|
|
|
|
fetchPokemonEvolutionChain,
|
|
|
|
|
} from '../api/pokemon'
|
2026-02-05 15:09:14 +01:00
|
|
|
|
|
|
|
|
export function usePokemon(id: number | null) {
|
|
|
|
|
return useQuery({
|
|
|
|
|
queryKey: ['pokemon', id],
|
|
|
|
|
queryFn: () => getPokemon(id!),
|
|
|
|
|
enabled: id !== null,
|
|
|
|
|
})
|
|
|
|
|
}
|
2026-02-07 21:08:25 +01:00
|
|
|
|
|
|
|
|
export function usePokemonFamilies() {
|
|
|
|
|
return useQuery({
|
|
|
|
|
queryKey: ['pokemon', 'families'],
|
|
|
|
|
queryFn: fetchPokemonFamilies,
|
|
|
|
|
staleTime: Infinity,
|
|
|
|
|
})
|
|
|
|
|
}
|
2026-02-08 14:03:43 +01:00
|
|
|
|
|
|
|
|
export function usePokemonEncounterLocations(pokemonId: number | null) {
|
|
|
|
|
return useQuery({
|
|
|
|
|
queryKey: ['pokemon', pokemonId, 'encounter-locations'],
|
|
|
|
|
queryFn: () => fetchPokemonEncounterLocations(pokemonId!),
|
|
|
|
|
enabled: pokemonId !== null,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function usePokemonEvolutionChain(pokemonId: number | null) {
|
|
|
|
|
return useQuery({
|
|
|
|
|
queryKey: ['pokemon', pokemonId, 'evolution-chain'],
|
|
|
|
|
queryFn: () => fetchPokemonEvolutionChain(pokemonId!),
|
|
|
|
|
enabled: pokemonId !== null,
|
|
|
|
|
})
|
|
|
|
|
}
|