You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: migrate useCollections hook to TanStack Query
- Refactor useCollections and the closely related useCollection hooks to
use TanStack Query for caching and fetching
- Improve error propagation, keep original loading states
- Update StacApiProvider to manage QueryClient and support custom clients
- Clarify peer dependency requirements for @tanstack/react-query in README
and docs/react-query-setup.md
- Update ESLint config and package.json for new dependencies
- Minor fixes to context and tests for compatibility
Copy file name to clipboardExpand all lines: README.md
+47-23Lines changed: 47 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,47 +19,75 @@ With Yarn:
19
19
yarn add @developmentseed/stac-react
20
20
```
21
21
22
+
### Peer Dependency: @tanstack/react-query
23
+
24
+
stac-react relies on [TanStack Query](https://tanstack.com/query/latest/docs/framework/react/overview) for data fetching and caching. To avoid duplicate React Query clients and potential version conflicts, stac-react lists `@tanstack/react-query` as a **peer dependency**. This means you must install it in your project:
25
+
26
+
```sh
27
+
npm install @tanstack/react-query
28
+
# or
29
+
yarn add @tanstack/react-query
30
+
```
31
+
32
+
If you do not install it, your package manager will warn you, and stac-react will not work correctly.
33
+
22
34
## Getting started
23
35
24
-
Stac-react's hooks must be used inside children of a React context that provides access to the stac-react's core functionality.
36
+
stac-react's hooks must be used inside children of a React context that provides access to the stac-react's core functionality.
25
37
26
-
To get started, initialize `StacApiProvider` with the base URL of the STAC catalog.
38
+
To get started, initialize `StacApiProvider` with the base URL of the STAC catalog.`StacApiProvider` automatically sets up a [TanStack Query](https://tanstack.com/query/latest/docs/framework/react/overview) QueryClientProvider for you, so you do not need to wrap your app with QueryClientProvider yourself.
stac-react relies on [TanStack Query](https://tanstack.com/query/latest/docs/framework/react/overview) for data fetching and caching. To avoid duplicate React Query clients and potential version conflicts, stac-react lists `@tanstack/react-query` as a **peer dependency**.
4
+
5
+
## Why peer dependency?
6
+
7
+
- Prevents multiple versions of React Query in your app.
8
+
- Ensures your app and stac-react share the same QueryClient instance.
9
+
- Follows best practices for React libraries that integrate with popular frameworks.
10
+
11
+
stac-react manages the QueryClient for you by default, but you can provide your own for advanced use cases.
12
+
13
+
**Important:** If your app uses multiple providers that require a TanStack QueryClient (such as `QueryClientProvider` and `StacApiProvider`), always use the same single QueryClient instance for all providers. This ensures that queries, mutations, and cache are shared across your app and prevents cache fragmentation or duplicate network requests.
0 commit comments