Last active
October 4, 2021 16:09
-
-
Save mwmwmw/a55927bc9bdf93660f604df341c45537 to your computer and use it in GitHub Desktop.
A React hook for querying OpenSea collections
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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