MCPcopy Create free account
hub / github.com/TanStack/query / Character

Function Character

examples/solid/star-wars-solid-router/src/Character.tsx:8–67  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6import { planetsQueries } from './services/planets/queries'
7
8export default function Character() {
9 const params = useParams<{ characterId: string }>()
10
11 const query = useQuery(() => charactersQueries.detail(params.characterId))
12
13 return (
14 <Switch>
15 <Match when={query.status === 'pending'}>
16 <p>Loading...</p>
17 </Match>
18 <Match when={query.status === 'error'}>
19 <p>Error :(</p>
20 </Match>
21 <Match when={query.data}>
22 {(data) => {
23 const homeworldId = () => {
24 const homeworldUrlParts = data()
25 .homeworld.split('/')
26 .filter(Boolean)
27 return homeworldUrlParts[homeworldUrlParts.length - 1]
28 }
29
30 return (
31 <div>
32 <h2 class="text-4xl">{data().name}</h2>
33 <p>
34 <strong>Born</strong>: {data().birth_year}
35 </p>
36 <p>
37 <strong>Eyes</strong>: {data().eye_color}
38 </p>
39 <p>
40 <strong>Hair</strong>: {data().hair_color}
41 </p>
42 <p>
43 <strong>Height</strong>: {data().height}
44 </p>
45 <p>
46 <strong>Mass</strong>: {data().mass}
47 </p>
48 <p>
49 <strong>Homeworld</strong>:{' '}
50 <Homeworld homeworldId={homeworldId()} />
51 </p>
52
53 <h4 class="text-2xl pt-4">Films</h4>
54 <For each={data().films}>
55 {(film) => {
56 const filmUrlParts = film.split('/').filter(Boolean)
57 const filmId = filmUrlParts[filmUrlParts.length - 1]
58 return <Film filmId={filmId} />
59 }}
60 </For>
61 </div>
62 )
63 }}
64 </Match>
65 </Switch>

Callers

nothing calls this directly

Calls 2

useQueryFunction · 0.90
homeworldIdFunction · 0.85

Tested by

no test coverage detected