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

Function App

examples/react/batching/src/index.tsx:62–109  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

60}
61
62function App() {
63 const [ids, setIds] = useState<Array<number>>([])
64 const [idsToLoad, setIdsToLoad] = useState<Array<number>>([])
65 const [error, setError] = useState('')
66
67 return (
68 <div className="App">
69 <h2>Character fetcher</h2>
70 <div>
71 <label style={{ display: 'block' }}>
72 Character ids (numeric, comma separated)
73 </label>
74 <input
75 style={{ display: 'inline-block' }}
76 placeholder="ids"
77 onChange={(event) => {
78 const parsedIds = event.target.value
79 .split(',')
80 .map((id) => id.trim())
81
82 if (parsedIds.every((id) => /^\d+$/.test(id))) {
83 setIds(parsedIds.map(Number))
84 setError('')
85 } else {
86 setError('Invalid.. only use numbers and comma')
87 }
88 }}
89 />
90 </div>
91
92 {error ? <h3 style={{ color: 'red' }}>{error}</h3> : null}
93
94 <button
95 type="button"
96 disabled={!!error}
97 onClick={() => {
98 setIdsToLoad(ids)
99 }}
100 >
101 Load characters
102 </button>
103 <div>
104 <h4 style={{ textAlign: 'left' }}>Characters:</h4>
105 <Characters ids={idsToLoad} />
106 </div>
107 </div>
108 )
109}
110
111function Root() {
112 return (

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected