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

Function SideNav

examples/solid/astro/src/components/SolidApp.tsx:191–250  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

189}
190
191const SideNav = () => {
192 const id = usePokemonID()
193
194 const pokemonsList = useQuery(() => ({
195 queryKey: ['pokemons'],
196 queryFn: async () => {
197 const res = await fetch(
198 `https://pokeapi.co/api/v2/pokemon?limit=${MAX_POKEMONS}`,
199 ).then((res) => res.json())
200 return res as {
201 results: { name: string; url: string }[]
202 }
203 },
204 select(data) {
205 return data.results.map((p) => {
206 const regex = /\/pokemon\/(\d+)\/$/
207 const match = p.url.match(regex)
208 const id = match ? match[1] : ''
209 return {
210 name: properCase(p.name),
211 id,
212 avatar: `https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/official-artwork/${id}.png`,
213 }
214 })
215 },
216 placeholderData: keepPreviousData,
217 reconcile: 'id',
218 }))
219
220 const activeClass = (pokemonID: string) =>
221 id() === pokemonID ? 'bg-gray-50' : 'hover:bg-gray-50'
222
223 return (
224 <div class="w-72 border-r flex flex-col px-2">
225 <div class="pt-3 pb-1 text-sm font-semibold">Pokemons</div>
226
227 <div class="flex-1 overflow-auto flex flex-col gap-1">
228 <For each={pokemonsList.data}>
229 {(pokemon) => (
230 <Link
231 class={`flex gap-2 items-center border rounded p-1 ${activeClass(
232 pokemon.id,
233 )}`}
234 href={`./?id=${pokemon.id}`}
235 >
236 <span class="flex bg-zinc-100 border relative justify-center items-center overflow-hidden rounded-sm w-9 h-9 flex-shrink-0">
237 <img
238 class="w-7 h-7 relative z-20"
239 src={pokemon.avatar}
240 alt={pokemon.name}
241 />
242 </span>
243 <span>{pokemon.name}</span>
244 </Link>
245 )}
246 </For>
247 </div>
248 </div>

Callers

nothing calls this directly

Calls 3

useQueryFunction · 0.90
usePokemonIDFunction · 0.85
activeClassFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…