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

Function App

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

Source from the content-addressed store, hash-verified

68}
69
70function App() {
71 const [ids, setIds] = useState<Array<number>>([])
72 const [idsToLoad, setIdsToLoad] = useState<Array<number>>([])
73 const [error, setError] = useState('')
74
75 return (
76 <div className="App">
77 <h2>Character fetcher</h2>
78 <div>
79 <label style={{ display: 'block' }}>
80 Character ids (numberic, comma seprated)
81 </label>
82 <input
83 style={{ display: 'inline-block' }}
84 placeholder="ids"
85 onChange={(event) => {
86 const text = event.target.value.replace(' ', '')
87 const ids = text.split(',').map((id) => parseInt(id, 10))
88 const allValid = ids.reduce(
89 (valid, id) => valid && !isNaN(id),
90 true,
91 )
92
93 if (allValid) {
94 setIds(ids)
95 setError('')
96 } else {
97 setError('Invalid.. only use numbers and comma')
98 }
99 }}
100 />
101 </div>
102
103 {error ? <h3 style={{ color: 'red' }}>{error}</h3> : null}
104
105 <button
106 type="button"
107 onClick={() => {
108 setIdsToLoad(ids)
109 }}
110 >
111 Load characters
112 </button>
113 <div>
114 <h4 style={{ textAlign: 'left' }}>Characters:</h4>
115 <Characters ids={idsToLoad} />
116 </div>
117 </div>
118 )
119}
120
121function Root() {
122 return (

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected