Documentation for agents: an index at /llms.txt, every docs page in one file at /llms-full.txt, and Markdown for any docs page by adding .md to its URL.

Skip to Content
ensforgeReact

Infinite lists

Page through an account's names, a name's subnames or a name's history with load-more hooks that read from an ENS indexer.

List hooks load an indexer list one page at a time, for "load more" buttons and infinite scroll. They need an indexer on the client. Without one, the read fails with INDEXER_NOT_CONFIGURED.

Add an indexer to the client

Pass indexer to Ensforge.create: bigname(), goldsky(), fallback([...]) or defineIndexer({...}) from @ensforge/sdk/indexer. See Connect an indexer.

Example (A Client With An Indexer)

providers.tsx
import type { ReactNode } from "react";

import { EnsforgeProvider } from "@ensforge/react";
import { Ensforge } from "@ensforge/sdk";
import { goldsky } from "@ensforge/sdk/indexer";
import { createPublicClient, http } from "viem";
import { mainnet } from "viem/chains";

const ens = Ensforge.create({
  publicClient: createPublicClient({ chain: mainnet, transport: http() }),
  indexer: goldsky(),
});

export function Providers({ children }: { children: ReactNode }) {
  return <EnsforgeProvider client={ens}>{children}</EnsforgeProvider>;
}

Show a list with "Load more"

useSubnames lists a name's subnames. It returns every item loaded so far in items, and loadMore fetches the next page.

Example (Subnames With A Load More Button)

Subnames.tsx
import { useSubnames } from "@ensforge/react";

export function Subnames({ name }: { name: string }) {
  const { items, hasMore, loadMore, isLoading, isLoadingMore, error } = useSubnames({ name });

  if (isLoading) return <p>Loading...</p>;
  if (error) return <p>{error.message}</p>;
  return (
    <>
      <ul>
        {items.map((item) => (
          <li key={item.name}>{item.name}</li>
        ))}
      </ul>
      {hasMore && (
        <button disabled={isLoadingMore} onClick={loadMore}>
          Load more
        </button>
      )}
    </>
  );
}
FieldMeaning
pagesEvery page loaded so far.
itemsThe items of every page, in order.
hasMoreMore pages remain.
loadMoreLoads the next page.
isLoadingThe first page is loading.
isLoadingMoreA further page is loading.
errorThe action's error when it failed.

Pick a list hook

HookLists
useSubnamesA name's subnames.
useNamesForAddressNames an address owns, manages or is the primary name of.
useNameHistoryA name's events: registrations, transfers and record changes.

For any other paginated indexer action, use useInfiniteRead(action, options, config). The action must return { items, cursor } and take a cursor, as Actions.indexer.getSubnames does. Leave cursor out of the options: the hook manages it.

Example (Any Paginated Action)

SearchSubnames.tsx
import { useInfiniteRead } from "@ensforge/react";
import { Actions } from "@ensforge/sdk";

export function SearchSubnames({ name, search }: { name: string; search: string }) {
  const { items, hasMore, loadMore } = useInfiniteRead(Actions.indexer.getSubnames, {
    name,
    search,
  });

  return (
    <>
      {items.map((item) => (
        <p key={item.name}>{item.name}</p>
      ))}
      {hasMore && <button onClick={loadMore}>Load more</button>}
    </>
  );
}

Wait for input and keep lists fresh

Pass undefined options, or enabled: false in the config, to hold the list back, as with read hooks. The config takes enabled and client only.

A write that touches the list's name or account starts the list over once the indexer has caught up, so a new subname appears without a manual refresh. See Caching and refreshing.

For the same lists outside React, see Load more results.

Was this page helpful?