Skip to main content

Fetch Collection

fetch collection details of any given collection.

Import fetchCollection using const { fetchCollection } = MetastaqInstance and pass the collection id for which you want to fetch nfts.

fetchCollection
import React from "react";
import { MetastaqInstance } from "./MetastaqInstance";

export const ShowCollections = () => {
const { status, data, error, isFetching, isLoading, refetch } =
fetchCollection(COLLECTION_ID);

return (
<button
onClick={() => {
refetch();
}}
>
refetch collections
</button>
);
};

COLLECTION_ID is the ID of the collection whose data you want to retrieve. The fetchCollection method returns status, data, error, isFetching, isLoading, refetch, where data is the collection-related data, status tells you the success or failure status of the response, the error tells you the error message, isFetching and isLoading are boolean values that tell you whether or not the request is still running. The refetch method allows you to retrieve the response again if you want to update the status when you click the button.