@@ -157,8 +157,6 @@ if (error && error.status === 404) {
157157** After:**
158158
159159``` typescript
160- import type { ApiErrorType } from ' stac-react' ;
161-
162160const { error } = useCollection (' my-collection' );
163161
164162if (error ?.status === 404 ) {
@@ -176,13 +174,11 @@ if (error?.status === 404) {
176174** What's different?**
177175
178176- Errors are now proper class instances with ` ApiError `
179- - Better TypeScript support with ` ApiErrorType `
180177- Includes HTTP status codes and response details
181178- Consistent across all hooks
182179
183180** Migration checklist:**
184181
185- - [ ] Import ` ApiErrorType ` from 'stac-react'
186182- [ ] Update error checks to use typed properties
187183- [ ] Test error scenarios (404, 500, network failures)
188184
@@ -196,7 +192,7 @@ The most significant changes are in `useStacSearch`:
196192
197193#### Before: Manual State Management
198194
199- ``` typescript
195+ ``` tsx
200196function MySearch() {
201197 const {
202198 state,
@@ -226,7 +222,7 @@ function MySearch() {
226222
227223#### After: TanStack Query Integration
228224
229- ``` typescript
225+ ``` tsx
230226function MySearch() {
231227 const {
232228 isLoading,
@@ -347,7 +343,7 @@ You now must configure TanStack Query. The library doesn't do this for you (to a
347343
348344#### Before
349345
350- ``` jsx
346+ ``` tsx
351347import { StacApiProvider } from ' stac-react' ;
352348
353349function App() {
@@ -357,7 +353,7 @@ function App() {
357353
358354#### After
359355
360- ``` jsx
356+ ``` tsx
361357import { QueryClient , QueryClientProvider } from ' @tanstack/react-query' ;
362358import { StacApiProvider } from ' stac-react' ;
363359
@@ -426,7 +422,7 @@ const { collection: col2 } = useCollection('landsat-8');
426422
427423### Request Deduplication
428424
429- ``` typescript
425+ ``` tsx
430426// Multiple components request same collection
431427// Only ONE network request is made, even if 5 components use the hook
432428
@@ -438,7 +434,7 @@ const { collection: col2 } = useCollection('landsat-8');
438434
439435### Invalidation on API Change
440436
441- ``` typescript
437+ ``` tsx
442438// If API URL changes, all queries are automatically invalidated
443439<StacApiProvider apiUrl = " https://old-api.com" />
444440// Switch to new API:
@@ -469,7 +465,7 @@ test('loads collections', async () => {
469465
470466### After
471467
472- ``` typescript
468+ ``` tsx
473469import { renderHook , waitFor } from ' @testing-library/react' ;
474470import { QueryClient , QueryClientProvider } from ' @tanstack/react-query' ;
475471import { useCollections } from ' stac-react' ;
@@ -518,13 +514,13 @@ If you're using TypeScript, new types are available:
518514
519515``` typescript
520516import type {
521- ApiErrorType , // Error response
522517 FetchRequest , // Request types for useStacSearch
523518 SearchRequestPayload , // Search parameters
524519} from ' stac-react' ;
525520
526521// Your hook usage
527- const { error }: { error? : ApiErrorType } = useCollection (' id' );
522+ // Error is of type ApiError
523+ const { error } = useCollection (' id' );
528524
529525if (error ) {
530526 console .log (error .status ); // number
@@ -541,15 +537,15 @@ if (error) {
541537
542538** Before:**
543539
544- ``` typescript
540+ ``` tsx
545541{state === ' LOADING' && <Skeleton />}
546542{state === ' IDLE' && results && <Results items = { results .features } />}
547543{error && <Error message = { error .message } />}
548544```
549545
550546** After:**
551547
552- ``` typescript
548+ ``` tsx
553549{isLoading && <Skeleton />}
554550{! isLoading && results && <Results items = { results .features } />}
555551{error && <Error message = { error .statusText } />}
@@ -559,15 +555,15 @@ if (error) {
559555
560556** Before:**
561557
562- ``` typescript
558+ ``` tsx
563559<button onClick = { search } disabled = { state === ' LOADING' } >
564560 Search
565561</button >
566562```
567563
568564** After:**
569565
570- ``` typescript
566+ ``` tsx
571567<button onClick = { search } disabled = { isLoading || isFetching } >
572568 { isFetching ? ' Searching...' : ' Search' }
573569</button >
@@ -678,7 +674,6 @@ const testClient = new QueryClient({
678674- [ ] Replace ` state ` with ` isLoading ` /` isFetching ` in all components
679675- [ ] Rename ` reload ` to ` refetch ` in all components
680676- [ ] Replace context data access with individual hooks
681- - [ ] Update error handling to use typed ` ApiErrorType `
682677- [ ] Update tests to use test QueryClient
683678- [ ] Remove context data subscriptions
684679- [ ] Review caching strategy for your app
0 commit comments