Skip to main content
The useCustomer hook fetches customer profile data and feature access in one request. If the customer does not exist yet, PriceOS will create it automatically.
Setup first: see the React integration guide.

Parameters

boolean
Enable or disable fetching. Defaults to true.
boolean
When true, a 404 is surfaced as an error instead of returning null. Defaults to false.
SWRConfiguration<PriceOSCustomer<MyFeatures> | null, Error>
Optional SWR config for caching/revalidation behavior.

Returns

PriceOSCustomer<MyFeatures> | null
Customer data including profile fields and featureAccess.
boolean
Whether data is currently loading.
Error | null
Error from the latest request.
() => Promise<void>
Manually revalidate customer data.
(body) => Promise<TrackUsageResponse>
Tracks usage and revalidates customer and feature-access caches.
(body) => Promise<CreateCheckoutResponse>
Creates a checkout session and redirects to Stripe Checkout.
(body?) => Promise<CreateCustomerPortalResponse>
Creates a customer portal session and redirects to Stripe Customer Portal.

trackUsage body

string
required
Feature key to track usage for (typed to your tracked limit feature keys when using generated types).
number
Usage amount to record. Defaults to 1.
string
Stable event key for retries and deduplication.
number
Unix timestamp in milliseconds for when the event happened.
Record<string, string>
Optional string key/value metadata attached to the usage event.
When using built-in Next.js handlers (priceos/next), client hook calls must use a positive amount. For negative adjustments, track usage on your backend with the Node.js SDK or REST API.

Examples