Skip to main content

Hooks

React hooks for programmatic access to UpsellSDK.

useUpsell

Access the SDK context for tracking and identifying:

import { useUpsell } from '@upsellsdk/react'

function MyComponent() {
const { track, identify, user } = useUpsell()

const handleExport = () => {
track('export_attempted', { format: 'csv' })
// ... do export
}

return (
<button onClick={handleExport}>
Export as CSV
</button>
)
}

Return Value

PropertyTypeDescription
trackfunctionTrack an event
identifyfunctionIdentify a user
userobjectCurrent user info
openUpgradeModalfunctionOpen the upgrade modal

useFeature

Check feature access and get an upgrade function:

import { useFeature } from '@upsellsdk/react'

function AnalyticsButton() {
const { allowed, requestAccess } = useFeature('analytics')

const handleClick = () => {
if (allowed) {
navigate('/analytics')
} else {
requestAccess() // Shows upgrade modal
}
}

return (
<button onClick={handleClick}>
View Analytics
{!allowed && <span className="badge">Pro</span>}
</button>
)
}

Parameters

ParameterTypeDescription
featureKeystringThe feature to check

Return Value

PropertyTypeDescription
allowedbooleanWhether user has access
requestAccessfunctionOpens upgrade modal