Skip to content

Commit d01d658

Browse files
committed
docs: Add useStacApi docs
1 parent 0b6a69a commit d01d658

File tree

1 file changed

+65
-12
lines changed

1 file changed

+65
-12
lines changed

README.md

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ yarn add @developmentseed/stac-react
2424

2525
### StacApi
2626

27+
**Removed in 0.1.0-alpha.6:** Do not instanciate `StacApi` directly. Use the `useStacApi` hook instead.
28+
2729
Initialises a STAC-API client. Pass the instance to the React hooks as documented below.
2830

2931
#### Example
@@ -113,6 +115,57 @@ function CollectionList() {
113115
}
114116
```
115117

118+
### useStacApi
119+
120+
Initialises a StacAPI instance.
121+
122+
#### Initialization
123+
124+
```js
125+
import { useStacApi } from "stac-react";
126+
const { stacApi } = useStacApi("https://planetarycomputer.microsoft.com/api/stac/v1");
127+
```
128+
129+
#### Options
130+
131+
Option | Type | Default | Description
132+
--------------- | --------- | -------- | -------------
133+
`url` | `string` | | Required. The endpoint of the STAC API you want to connect to.
134+
135+
#### Return values
136+
137+
Option | Type | Description
138+
--------------- | --------- | -------------
139+
`stacApi` | Instance of `StacApi` | An object that you can pass to `useCollections` and `useStacSearch` hooks.
140+
141+
#### Example
142+
143+
```jsx
144+
import { useCallback } from "react";
145+
import { useStacApi, useStacSearch } from "stac-react";
146+
147+
import Map from "./map";
148+
149+
function StacComponent() {
150+
const { stacApi } = useStacApi("https://planetarycomputer.microsoft.com/api/stac/v1");
151+
const { result } = useStacSearch(stacApi);
152+
153+
return (
154+
<>
155+
<div class="item-list">
156+
{results && (
157+
<ul>
158+
{results.features.map(({ id }) => (
159+
<li key={id}>{ id }</li>
160+
))}
161+
</ul>
162+
)}
163+
</div>
164+
</>
165+
)
166+
}
167+
```
168+
116169
### useStacSearch
117170

118171
Executes a search against a STAC API using the provided search parameters.
@@ -155,12 +208,12 @@ Option | Type | Description
155208

156209
```jsx
157210
import { useCallback } from "react";
158-
import { StacApi, useStacSearch } from "stac-react";
211+
import { useStacApi, useStacSearch } from "stac-react";
159212

160213
import Map from "./map";
161214

162215
function StacComponent() {
163-
const stacApi = new StacApi("https://planetarycomputer.microsoft.com/api/stac/v1");
216+
const { stacApi } = useStacApi("https://planetarycomputer.microsoft.com/api/stac/v1");
164217
const { result } = useStacSearch(stacApi);
165218

166219
return (
@@ -183,12 +236,12 @@ function StacComponent() {
183236

184237
```jsx
185238
import { useCallback } from "react";
186-
import { StacApi, useStacSearch } from "stac-react";
239+
import { useStacApi, useStacSearch } from "stac-react";
187240

188241
import Map from "./map";
189242

190243
function StacComponent() {
191-
const stacApi = new StacApi("https://planetarycomputer.microsoft.com/api/stac/v1");
244+
const { stacApi } = useStacApi("https://planetarycomputer.microsoft.com/api/stac/v1");
192245
const { error, result } = useStacSearch(stacApi);
193246

194247
return (
@@ -212,12 +265,12 @@ function StacComponent() {
212265

213266
```jsx
214267
import { useCallback } from "react";
215-
import { StacApi, useStacSearch } from "stac-react";
268+
import { useStacApi, useStacSearch } from "stac-react";
216269

217270
import Map from "./map";
218271

219272
function StacComponent() {
220-
const stacApi = new StacApi("https://planetarycomputer.microsoft.com/api/stac/v1");
273+
const { stacApi } = useStacApi("https://planetarycomputer.microsoft.com/api/stac/v1");
221274
const {
222275
nextPage,
223276
previousPage,
@@ -244,10 +297,10 @@ function StacComponent() {
244297

245298
```jsx
246299
import { useCallback } from "react";
247-
import { StacApi, useStacSearch } from "stac-react";
300+
import { useStacApi, useStacSearch } from "stac-react";
248301

249302
function StacComponent() {
250-
const stacApi = new StacApi("https://planetarycomputer.microsoft.com/api/stac/v1");
303+
const { stacApi } = useStacApi("https://planetarycomputer.microsoft.com/api/stac/v1");
251304
const { collections } = useCollections(stacApi);
252305
const { collections: selectedCollections, setCollections, results, submit } = useStacSearch(stacApi);
253306

@@ -291,12 +344,12 @@ function StacComponent() {
291344

292345
```jsx
293346
import { useCallback } from "react";
294-
import { StacApi, useStacSearch } from "stac-react";
347+
import { useStacApi, useStacSearch } from "stac-react";
295348

296349
import Map from "./map";
297350

298351
function StacComponent() {
299-
const stacApi = new StacApi("https://planetarycomputer.microsoft.com/api/stac/v1");
352+
const { stacApi } = useStacApi("https://planetarycomputer.microsoft.com/api/stac/v1");
300353
const { bbox, setBbox, submit } = useStacSearch(stacApi);
301354

302355
const handleDrawComplete = useCallback((feature) => {
@@ -317,12 +370,12 @@ This example assumes that a `Map` component handles drawing and calls `handleDra
317370

318371
```jsx
319372
import { useCallback } from "react";
320-
import { StacApi, useStacSearch } from "stac-react";
373+
import { useStacApi, useStacSearch } from "stac-react";
321374

322375
import Map from "./map";
323376

324377
function StacComponent() {
325-
const stacApi = new StacApi("https://planetarycomputer.microsoft.com/api/stac/v1");
378+
const { stacApi } = useStacApi("https://planetarycomputer.microsoft.com/api/stac/v1");
326379
const {
327380
dateRangeFrom,
328381
setDateRangeFrom,

0 commit comments

Comments
 (0)