Skip to main content

useRevstack

Returns the RevstackClient instance from context. Signature
function useRevstack(): RevstackClient
Returns
  • RevstackClient - The client instance configured in <RevstackProvider>
Throws
  • Error if used outside of <RevstackProvider>
Usage
import { useRevstack } from '@revstackhq/react';

function MyComponent() {
  const client = useRevstack();
  
  const handleCheckout = async () => {
    await client.startCheckout({
      planId: 'plan_123',
      successUrl: '/success',
      cancelUrl: '/pricing',
    });
  };

  return <button onClick={handleCheckout}>Subscribe</button>;
}

useEntitlement

Subscribes to entitlement changes and returns the current state for a feature. Signature
function useEntitlement(key: string): Entitlement
Parameters
  • key (string) - The feature key to check
Returns
  • Entitlement object with:
    • key (string) - The feature key
    • hasAccess (boolean) - Whether the user has access
    • value? (string | number | boolean) - Optional limit or configuration value
SSR Safe This hook uses useSyncExternalStore with a server snapshot that returns { key, hasAccess: false }, preventing hydration mismatches in Next.js and Remix. Usage
import { useEntitlement } from '@revstackhq/react';

function FeatureGate() {
  const entitlement = useEntitlement('premium-feature');

  if (!entitlement.hasAccess) {
    return <UpgradePrompt />;
  }

  return <PremiumFeature />;
}
Notes
  • Updates automatically when entitlements change
  • Safe for server-side rendering
  • Returns hasAccess: false during initial load and on server

Build docs developers (and LLMs) love