RevstackProvider
Context provider that initializes and manages the Revstack client instance.
Props
Configuration object for the Revstack client Show RevstackConfig properties
Your project’s public key from the Revstack dashboard
getToken
() => Promise<string | null>
required
Async function that returns the current user’s JWT token, or null if unauthenticated
Custom API base URL (defaults to https://app.revstack.dev)
Custom guest ID resolver - overrides the default fingerprinting logic
Set to true to skip browser fingerprinting entirely
Your application components
Behavior
Instantiates RevstackClient once and keeps it stable across re-renders
Automatically calls client.init() on mount to fetch entitlements
Provides the client instance to all child components via context
Logs initialization errors to console (non-blocking)
Usage
Basic Setup
With Auth Integration
Anonymous Users Only
import { RevstackProvider } from '@revstackhq/react' ;
function App () {
const config = {
publicKey: process . env . NEXT_PUBLIC_REVSTACK_KEY ! ,
getToken : async () => {
// Return your auth token or null
return localStorage . getItem ( 'auth_token' );
},
};
return (
< RevstackProvider config = { config } >
< YourApp />
</ RevstackProvider >
);
}
Best Practices
The config object should be memoized or defined outside the component to prevent unnecessary re-initialization: // ❌ Bad - creates new config on every render
function App () {
return (
< RevstackProvider config = { { publicKey: '...' , getToken : async () => null } } >
{ children }
</ RevstackProvider >
);
}
// ✅ Good - stable config reference
const config = { publicKey: '...' , getToken : async () => null };
function App () {
return (
< RevstackProvider config = { config } >
{ children }
</ RevstackProvider >
);
}
Place <RevstackProvider> high in your component tree, typically at the root of your application, so all components can access hooks like useRevstack() and useEntitlement().