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

Function Characters

examples/react/batching/src/index.tsx:27–68  ·  view source on GitHub ↗
({ ids }: { ids: Array<number> })

Source from the content-addressed store, hash-verified

25 })
26
27function Characters({ ids }: { ids: Array<number> }) {
28 const characters = useQueries({
29 queries: ids.map((id) => characterQueryOptions(id)),
30 })
31
32 return characters.map((character, index) => {
33 if (character.status === 'pending') {
34 return 'Loading...'
35 }
36 if (character.status === 'error') {
37 return 'Error...'
38 }
39 if (character.data === null) {
40 return 'Not found ...'
41 }
42
43 return (
44 <div key={String(index)} style={{ display: 'flex' }}>
45 <img
46 width={100}
47 height={100}
48 alt={character.data.image}
49 src={character.data.image}
50 />
51 <div style={{ paddingLeft: 10, textAlign: 'left' }}>
52 <h5 style={{ marginTop: 0, marginBottom: 5 }}>
53 {character.data.name} (#{character.data.id})
54 </h5>
55 <p style={{ marginTop: 0, marginBottom: 2 }}>
56 Status: {character.status}
57 </p>
58 <p style={{ marginTop: 0, marginBottom: 2 }}>
59 Species: {character.data.species}
60 </p>
61 <p style={{ marginTop: 0, marginBottom: 2 }}>
62 Gender: {character.data.gender}
63 </p>
64 </div>
65 </div>
66 )
67 })
68}
69
70function App() {
71 const [ids, setIds] = useState<Array<number>>([])

Callers

nothing calls this directly

Calls 2

useQueriesFunction · 0.90
characterQueryOptionsFunction · 0.85

Tested by

no test coverage detected