User Hooks
Hooks for reading and updating user identity fields.
useUser()
Read and update built-in user fields. Only re-renders when a user.* variable changes.
const { email, setEmail, identify, marketingConsent, setMarketingConsent } = useUser()
// Update email field
setEmail('user@example.com')
// Identify the user (fires user.registered event)
identify(email)
// Track marketing consent
setMarketingConsent(true)| Property | Type | Description |
|---|---|---|
email | string | User email address |
name | string | User display name |
dateOfBirth | string | Date of birth in YYYY-MM-DD format |
marketingConsent | boolean | Whether the user has opted in to marketing emails |
stripeCustomerId | string | Stripe customer ID (set after payment) |
paddleCustomerId | string | Paddle customer ID (set after payment) |
setEmail | (email: string) => void | Update email |
setName | (name: string) => void | Update name |
setDateOfBirth | (dob: string) => void | Update date of birth (auto-converts to ISO) |
setMarketingConsent | (consent: boolean) => void | Set marketing email consent |
identify | (email: string) => void | Associate the session with an email (fires user.registered event) |
useUserProperty(field)
Read/write a custom user property. Auto-prefixed with user. — no config declaration needed.
const [gender, setGender] = useUserProperty('gender')| Return | Type | Description |
|---|---|---|
[0] | string | Current property value |
[1] | (value: string) => void | Setter function |
useDateOfBirth(format?)
Format-aware date of birth input. Always stores the value as ISO YYYY-MM-DD regardless of input format.
const [dob, setDob] = useDateOfBirth() // defaults to MM/DD/YYYY
const [dob, setDob] = useDateOfBirth('DD/MM/YYYY') // EU format
setDob('03/15/1990') // stored as "1990-03-15"
setDob('03151990') // stored as "1990-03-15"Supported formats: 'MM/DD/YYYY' (default), 'DD/MM/YYYY', 'YYYY-MM-DD'
| Return | Type | Description |
|---|---|---|
[0] | string | Current DOB in YYYY-MM-DD format |
[1] | (value: string) => void | Setter — parses input using the specified format |
Last updated on