Import

import { useListPrimarySaleItems } from "@0xsequence/marketplace-sdk";

Usage

import { useListPrimarySaleItems } from "@0xsequence/marketplace-sdk";

function App() {
  const { data, isLoading, hasNextPage, fetchNextPage, isFetchingNextPage } =
    useListPrimarySaleItems({
      chainId: 137,
      primarySaleContractAddress: "0x123...",
      page: {
        pageSize: 20,
      },
    });

  if (isLoading) {
    return <div>Loading...</div>;
  }

  return (
    <div>
      {data?.pages.map((page, i) => (
        <div key={i}>
          {page.items.map((item) => (
            <div key={item.id}>
              {item.name} - {item.price}
            </div>
          ))}
        </div>
      ))}

      {hasNextPage && (
        <button onClick={() => fetchNextPage()} disabled={isFetchingNextPage}>
          {isFetchingNextPage ? "Loading more..." : "Load More"}
        </button>
      )}
    </div>
  );
}

Return Type: UseInfiniteQueryResult

The hook returns a React Query infinite query result object with the following key properties:
type UseInfiniteQueryResult = {
  data: {
    pages: Array<{
      items: PrimarySaleItem[];
      nextCursor?: string;
    }>;
    pageParams: unknown[];
  };
  isLoading: boolean;
  error: Error | null;
  hasNextPage: boolean;
  fetchNextPage: () => Promise<void>;
  isFetchingNextPage: boolean;
  // ... other React Query infinite query properties
};

Parameters

ParameterTypeDescription
chainIdnumberThe chain ID (e.g., 1 for Ethereum, 137 for Polygon)
primarySaleContractAddressstringThe primary sale contract address
filterobject(Optional) Filter parameters for the query
filter.statusstring(Optional) Filter by item status (e.g., ‘active’)
pageobject(Optional) Pagination configuration
page.pageSizenumber(Optional) Number of items per page
queryobject(Optional) React Query configuration options
configobject(Optional) SDK configuration options

Query Options

You can customize the query behavior using the optional parameters:
const { data, isLoading } = useListPrimarySaleItems({
  chainId: 1,
  primarySaleContractAddress: "0x...",
  filter: {
    status: "active",
  },
  page: {
    pageSize: 20,
  },
  query: {
    enabled: isReady,
    refetchInterval: 30000, // Refetch every 30 seconds
  },
});

Notes

This hook is useful for:
  • Displaying a list of primary sale items with infinite scroll
  • Building marketplace primary sale pages
  • Showing available items for initial sale
  • Managing paginated data loading
The hook automatically handles:
  • Infinite scrolling pagination
  • Data fetching and caching
  • Loading and error states
  • Type-safe responses
Make sure to handle the loading states appropriately, especially isFetchingNextPage when implementing infinite scroll functionality.
The primarySaleContractAddress must be a valid contract address that supports primary sales. Invalid addresses will result in failed queries.