Improve `useItem` API to accept collection and item IDs instead of full URL
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- react, typescript
Research direction
Start by reading the existing useItem and useCollection hooks, then inspect StacApiProvider and useStacApiContext to understand how the base URL is exposed. Define the new collection and item ID signature, update the hook's callers, documentation, examples, and migration guidance, and verify that the query uses the constructed collection-item path.
Written by the indexing model from the issue text.
Description
The current useItem hook requires users to pass the full URL of an item, which is redundant and inconsistent with other hooks in the library:
// Current API
const { item } = useItem('https://stac-catalog.com/collections/sentinel-2/items/abc123');
This design has several issues:
- Redundancy: The
StacApiProvideralready knows the base API URL, yet users must construct the full URL themselves - Error-prone: Manual URL construction can lead to mistakes (typos, wrong separators, encoding issues)
- Not portable: Hardcoded URLs make switching between environments (dev/staging/prod) difficult
- Inconsistent API:
useCollectiontakes just acollectionId, butuseItemrequires a full URL
Proposed Solution
Refactor useItem to accept collectionId and itemId parameters, then construct the URL internally using the stacApi from context:
// Proposed API
const { item } = useItem('sentinel-2', 'abc123');
// Or with an object for clarity:
const { item } = useItem({ collectionId: 'sentinel-2', itemId: 'abc123' });
This follows the STAC API spec pattern: /collections/{collectionId}/items/{itemId}
Benefits
- Consistency: Matches the pattern used by
useCollection - Simplicity: No manual URL construction required
- Portability: Environment-agnostic (base URL comes from context)
- Type safety: Parameters are clearly defined
- Less error-prone: Reduces chance of URL construction mistakes
Implementation Details
The hook would:
- Accept
collectionIdanditemIdas parameters - Get
stacApifromuseStacApiContext() - Construct the URL using
stacApi.baseUrl+/collections/${collectionId}/items/${itemId} - Use this constructed URL for the query
Breaking Change
⚠️ This is a breaking change that would require a major version bump.
The hook could detect which signature is being used based on the number/type of arguments.
Related
- Consider whether other hooks might benefit from similar improvements
- Update documentation and examples
- Add migration guide if this is a breaking change
- Dominant language
- TypeScript
- Stars
- 34
- Forks
- 4
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from developmentseed/stac-react
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
All issues in developmentseed/stac-react
Similar issues
-
Browser Waiting for: Product Owner
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
getsentry/sentry-javascript#24577 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
agilepathway/label-checker#640 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
copse-dev/agent-pane#2953 ·
-
agentic-workflows
Difficulty 1/5 Under an hour Newbie friendliness 85/100
githubnext/rig#534 ·
-
automation missing-model model-sync provider:pioneer
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
anomalyco/models.dev#7701 ·