MCPcopy
hub / github.com/TanStack/query / PokemonDex

Function PokemonDex

examples/solid/astro/src/components/SolidApp.tsx:74–189  ·  view source on GitHub ↗
(props: { id: string })

Source from the content-addressed store, hash-verified

72}
73
74const PokemonDex = (props: { id: string }) => {
75 const pokemon = useQuery(() => ({
76 queryKey: ['pokemon', props.id],
77 queryFn: async () => {
78 const res = await fetch(
79 `https://pokeapi.co/api/v2/pokemon/${props.id}`,
80 ).then((res) => res.json())
81 return res
82 },
83 placeholderData: keepPreviousData,
84 }))
85
86 const pokemon_stats = useQuery(() => ({
87 queryKey: ['pokemon', props.id],
88 queryFn: async () => {
89 const res = await fetch(
90 `https://pokeapi.co/api/v2/pokemon/${props.id}`,
91 ).then((res) => res.json())
92
93 return res
94 },
95 select(data) {
96 const nameMap = {
97 hp: 'HP',
98 attack: 'Attack',
99 defense: 'Defense',
100 'special-attack': 'Special Attack',
101 'special-defense': 'Special Defense',
102 speed: 'Speed',
103 }
104 const stats = data.stats.map((stat: any) => ({
105 name: nameMap[stat.stat.name as keyof typeof nameMap],
106 value: stat.base_stat,
107 }))
108 return stats as { name: string; value: number }[]
109 },
110 placeholderData: keepPreviousData,
111 reconcile: 'name',
112 }))
113
114 const is_server_rendered = useQuery(() => ({
115 queryKey: ['is_server_rendered', props.id],
116 queryFn: () => {
117 if (isServer) return true
118 return false
119 },
120 placeholderData: keepPreviousData,
121 }))
122
123 return (
124 <div class="flex flex-col flex-1">
125 <Show when={pokemon.data}>
126 <div class="flex justify-center text-3xl font-semibold py-4">
127 {properCase(pokemon.data.name)}
128 </div>
129 <div class="flex justify-center">
130 <div class="h-64 w-64 rounded-lg relative overflow-hidden border">
131 <img

Callers

nothing calls this directly

Calls 2

useQueryFunction · 0.90
properCaseFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…