Skip to content

Instantly share code, notes, and snippets.

@mwmwmw
Last active October 4, 2021 16:09
Show Gist options
  • Save mwmwmw/a55927bc9bdf93660f604df341c45537 to your computer and use it in GitHub Desktop.
Save mwmwmw/a55927bc9bdf93660f604df341c45537 to your computer and use it in GitHub Desktop.
A React hook for querying OpenSea collections
import { useEffect, useState } from 'react';
const options = { method: 'GET' };
export default function useOpenSeaCollections({
owner,
offset = 0,
limit = 50,
}) {
const [collections, setCollections] = useState([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
setLoading(true);
fetch(
`https://api.opensea.io/api/v1/collections?asset_owner=${owner}&offset=${offset}&limit=${limit}`,
options,
)
.then((response) => response.json())
.then((response) => setCollections(response))
.then(() => setLoading(false))
.catch((err) => console.error(err));
}, [owner, offset, limit]);
return {
collections,
loading,
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment