šŸ“ Sign Up | šŸ” Log In

← Root | ↑ Up

ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā” │ šŸ“„ shadcn/directory/clerk/clerk-docs/reference/hooks/use-statements │ ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜

╔══════════════════════════════════════════════════════════════════════════════════════════════╗
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘

title: 'useStatements()' description: Access and manage statements in your React application with Clerk's useStatements() hook. sdk: nextjs, react

<Include src="_partials/billing/billing-experimental" />

The useStatements() hook provides access to the statements associated with a user or organization. It returns a paginated list of statements and includes methods for managing them.

Parameters

useStatements() accepts a single object with the following properties:

<Properties> - `for?` - `'user' | 'organization'`

Specifies whether to fetch statements for the current user or organization. Defaults to 'user'.


  • pageSize?
  • number

The number of statements to fetch per page. Defaults to 10.


  • initialPage?
  • number

The page number to start fetching from. Defaults to 1.


  • infinite?
  • boolean

When true, enables infinite pagination mode where new pages are appended to existing data. When false, each page replaces the previous data. Defaults to false.


  • keepPreviousData?
  • boolean

When true, the previous data will be kept while loading the next page. This helps prevent layout shifts. Defaults to false. </Properties>

Returns

useStatements() returns an object with the following properties:

<Properties> - `data` - <code>[BillingStatementResource](/docs/reference/javascript/types/billing-statement-resource)\[] | null</code>

An array of statements, or null if the data hasn't been loaded yet.


  • isLoading
  • boolean

A boolean that is true if there is an ongoing request and there is no fetched data.


  • isFetching
  • boolean

A boolean that is true if there is an ongoing request or a revalidation.


  • hasNextPage
  • boolean

A boolean that indicates if there are available pages to be fetched.


  • hasPreviousPage
  • boolean

A boolean that indicates if there are available pages to be fetched.


  • fetchNext
  • <code>() => void</code>

A function that triggers the next page to be loaded. This is the same as fetchPage(page => Math.min(pageCount, page + 1)).


  • fetchPrevious
  • <code>() => void</code>

A function that triggers the previous page to be loaded. This is the same as fetchPage(page => Math.max(0, page - 1)).


  • pageCount
  • number

The total amount of pages. It is calculated based on count, initialPage, and pageSize.


  • count
  • number

The total number of statements available.


Returns an error object if any part of the process fails.


  • fetchPage
  • (page: number) => void

A function that triggers a specific page to be loaded.


  • isError
  • boolean

A boolean that indicates the request failed.


  • page
  • number

The current page.


  • revalidate
  • <code>() => Promise<void></code>

A function that triggers a revalidation of the current page.


  • setData
  • (data: any[]) => void

A function that allows you to set the data manually. </Properties>

Examples

Basic usage

The following example demonstrates how to fetch and display a user's statements.

import { useStatements } from '@clerk/nextjs/experimental'

function StatementsList() {
  const { data, isLoading } = useStatements({
    for: 'user',
    pageSize: 10,
  })

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

  if (!data || data.length === 0) {
    return <div>No statements found.</div>
  }

  return (
    <ul>
      {data?.map((statement) => (
        <li key={statement.id}>
          Statement ID: {statement.id} - {statement.status}
          <br />
          Date: {statement.timestamp.toLocaleDateString()}
        </li>
      ))}
    </ul>
  )
}

Infinite pagination

The following example demonstrates how to implement infinite scrolling with statements.

import { useStatements } from '@clerk/nextjs/experimental'

function InfiniteStatements() {
  const { data, isLoading, hasNextPage, fetchNext } = useStatements({
    for: 'user',
    infinite: true,
    pageSize: 20,
  })

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

  if (!data || data.length === 0) {
    return <div>No statements found.</div>
  }

  return (
    <div>
      <ul>
        {data?.map((statement) => (
          <li key={statement.id}>
            Statement ID: {statement.id}
            <br />
            Amount: {statement.totals.grandTotal.amountFormatted}
            <br />
            Status: {statement.status}
          </li>
        ))}
      </ul>

      {hasNextPage && <button onClick={() => fetchNext()}>Load more statements</button>}
    </div>
  )
}
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•‘
ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•

← Root | ↑ Up