useStatements()
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 optional object with the following properties:
Returns
useStatements() returns an object with the following properties:
- Name
-
data - Type
BillingStatementResource[]- Description
An array that contains the fetched data. For example, for the
membershipsattribute, data will be an array of OrganizationMembership objects.
- Name
-
setData - Type
CacheSetter<undefined | ClerkPaginatedResponse<BillingStatementResource>>- Description
A function that allows you to set the data manually.
Examples
Basic usage
The following example demonstrates how to fetch and display a user's statements.
'use client'
import { useStatements } from '@clerk/nextjs/experimental'
export default 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.
'use client'
import { useStatements } from '@clerk/nextjs/experimental'
export default 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>
)
}Feedback
Last updated on