Skip to main content

UpsellProvider

The UpsellProvider component initializes the SDK and provides context to child components.

Installation

npm install @upsellsdk/react

Usage

Wrap your app with UpsellProvider:

import { UpsellProvider } from '@upsellsdk/react'

function App() {
return (
<UpsellProvider
config={{
apiKey: 'us_your_api_key',
user: {
id: 'user-123',
email: 'user@example.com',
plan: 'free'
},
onUpgrade: () => {
window.location.href = '/pricing'
}
}}
>
<YourApp />
</UpsellProvider>
)
}

Props

PropTypeRequiredDescription
config.apiKeystringYesYour UpsellSDK API key
config.userobjectYesCurrent user info
config.user.idstringYesUser ID
config.user.emailstringNoUser email
config.user.planstringNoCurrent plan
config.onUpgradefunctionNoCalled when user clicks upgrade

With Dynamic User

Update user info when it changes:

function App() {
const { user, isLoading } = useAuth()

if (isLoading) return <Loading />

return (
<UpsellProvider
config={{
apiKey: process.env.UPSELLSDK_API_KEY,
user: user ? {
id: user.id,
email: user.email,
plan: user.subscription?.plan || 'free'
} : null,
onUpgrade: () => navigate('/pricing')
}}
>
<YourApp />
</UpsellProvider>
)
}