@@ -24,6 +24,8 @@ yarn add @developmentseed/stac-react
24
24
25
25
### StacApi
26
26
27
+ ** Removed in 0.1.0-alpha.6:** Do not instanciate ` StacApi ` directly. Use the ` useStacApi ` hook instead.
28
+
27
29
Initialises a STAC-API client. Pass the instance to the React hooks as documented below.
28
30
29
31
#### Example
@@ -113,6 +115,57 @@ function CollectionList() {
113
115
}
114
116
```
115
117
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
+
116
169
### useStacSearch
117
170
118
171
Executes a search against a STAC API using the provided search parameters.
@@ -155,12 +208,12 @@ Option | Type | Description
155
208
156
209
``` jsx
157
210
import { useCallback } from " react" ;
158
- import { StacApi , useStacSearch } from " stac-react" ;
211
+ import { useStacApi , useStacSearch } from " stac-react" ;
159
212
160
213
import Map from " ./map" ;
161
214
162
215
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" );
164
217
const { result } = useStacSearch (stacApi);
165
218
166
219
return (
@@ -183,12 +236,12 @@ function StacComponent() {
183
236
184
237
``` jsx
185
238
import { useCallback } from " react" ;
186
- import { StacApi , useStacSearch } from " stac-react" ;
239
+ import { useStacApi , useStacSearch } from " stac-react" ;
187
240
188
241
import Map from " ./map" ;
189
242
190
243
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" );
192
245
const { error , result } = useStacSearch (stacApi);
193
246
194
247
return (
@@ -212,12 +265,12 @@ function StacComponent() {
212
265
213
266
``` jsx
214
267
import { useCallback } from " react" ;
215
- import { StacApi , useStacSearch } from " stac-react" ;
268
+ import { useStacApi , useStacSearch } from " stac-react" ;
216
269
217
270
import Map from " ./map" ;
218
271
219
272
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" );
221
274
const {
222
275
nextPage ,
223
276
previousPage ,
@@ -244,10 +297,10 @@ function StacComponent() {
244
297
245
298
``` jsx
246
299
import { useCallback } from " react" ;
247
- import { StacApi , useStacSearch } from " stac-react" ;
300
+ import { useStacApi , useStacSearch } from " stac-react" ;
248
301
249
302
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" );
251
304
const { collections } = useCollections (stacApi);
252
305
const { collections: selectedCollections , setCollections , results , submit } = useStacSearch (stacApi);
253
306
@@ -291,12 +344,12 @@ function StacComponent() {
291
344
292
345
``` jsx
293
346
import { useCallback } from " react" ;
294
- import { StacApi , useStacSearch } from " stac-react" ;
347
+ import { useStacApi , useStacSearch } from " stac-react" ;
295
348
296
349
import Map from " ./map" ;
297
350
298
351
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" );
300
353
const { bbox , setBbox , submit } = useStacSearch (stacApi);
301
354
302
355
const handleDrawComplete = useCallback ((feature ) => {
@@ -317,12 +370,12 @@ This example assumes that a `Map` component handles drawing and calls `handleDra
317
370
318
371
``` jsx
319
372
import { useCallback } from " react" ;
320
- import { StacApi , useStacSearch } from " stac-react" ;
373
+ import { useStacApi , useStacSearch } from " stac-react" ;
321
374
322
375
import Map from " ./map" ;
323
376
324
377
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" );
326
379
const {
327
380
dateRangeFrom ,
328
381
setDateRangeFrom ,
0 commit comments