Overview
Autumn provides React hooks for managing customer data, subscriptions, plans, events, and referrals. All hooks are built on TanStack Query and return standard query results with additional methods.useCustomer
Fetches or creates an Autumn customer and provides billing actions.Parameters
boolean
If
true, throws an error when customer is not found instead of returning null.CustomerExpand[]
Array of fields to expand in the response (e.g.,
['subscriptions']).UseQueryOptions
TanStack Query options for customizing the query behavior.
Return Value
Returns a query result with customer data and billing methods:Customer | null | undefined
The customer object.
undefined while loading, null if not found.boolean
true while the initial query is loading.boolean
true if the query encountered an error.AutumnClientError | null
The error object if the query failed.
() => Promise<...>
Refetch the customer data.
Billing Methods
attach
Attaches a plan to the customer. Handles new subscriptions, upgrades, and downgrades.string
required
ID of the plan to attach.
Record<string, number>
Feature quantities to set (e.g.,
{ seats: 5 }).{ days: number }
Free trial configuration.
string[]
Discount codes to apply.
string
URL to redirect to after checkout.
boolean
Open checkout in a new tab instead of redirecting.
previewAttach
Previews billing changes without making any changes. Use this to show customers what they’ll be charged.updateSubscription
Updates an existing subscription. Use to modify feature quantities, cancel, or change plan configuration.string
required
ID of the plan to update.
Record<string, number>
New feature quantities.
'cancel'
Action to perform (currently only
'cancel' is supported).previewUpdateSubscription
Previews subscription update changes without applying them.check
Checks feature access and balance locally (no API call). This is computed from the customer data.string
required
ID of the feature to check.
boolean
Whether the customer has access to this feature.
number
Remaining balance for the feature (for usage-based features).
multiAttach
Attaches multiple plans in a single operation.setupPayment
Creates a payment setup session to add or update payment methods.openCustomerPortal
Opens the Stripe customer billing portal.useListPlans
Fetches all available plans.Parameters
UseQueryOptions
TanStack Query options.
Return Value
Plan[]
Array of plan objects.
isLoading, isError, error, refetch, etc.).
useListEvents
Fetches events for the current customer with pagination.Parameters
string
Filter events by feature ID.
number
default:"100"
Number of events per page.
{ start: Date, end: Date }
Custom date range for filtering events.
UseQueryOptions
TanStack Query options.
Return Value
Event[]
Array of event objects for the current page.
number
Current page number (0-indexed).
boolean
Whether more pages are available.
boolean
Whether previous pages exist.
() => void
Navigate to the next page.
() => void
Navigate to the previous page.
({ pageNum: number }) => void
Navigate to a specific page.
() => void
Reset to page 0.
useAggregateEvents
Aggregates events by time period or custom grouping.Parameters
string
required
Feature ID to aggregate events for.
string
Time range preset (e.g.,
'last_7_days', 'last_30_days', 'this_month').'hour' | 'day' | 'week' | 'month'
Aggregation interval.
string[]
Custom property to group by.
{ start: Date, end: Date }
Custom date range (overrides
range parameter).UseQueryOptions
TanStack Query options.
Return Value
AggregatedEvent[]
Array of aggregated data points.
number
Total aggregated value across all bins.
useReferrals
Manages referral codes for the current customer.Parameters
string
required
ID of the referral program.
UseQueryOptions
TanStack Query options. Note: Query is disabled by default, call
refetch() to create a code.Return Value
{ code: string } | undefined
The created referral code data.
() => Promise<...>
Create or fetch a new referral code.
(params: { code: string }) => Promise<...>
Redeem a referral code for the current customer.