Skip to main content

RevstackProvider

Context provider that initializes and manages the Revstack client instance. Props
config
RevstackConfig
required
Configuration object for the Revstack client
children
ReactNode
required
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
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().

Build docs developers (and LLMs) love