Skip to main content

Overview

The Stigg React SDK is a Javascript library for implementing pricing and packaging in React apps with Stigg. It provides plug-and-play components and custom React hooks. It’s built on top of the JavaScript SDK and is the recommended method for integrating Stigg into your React application.
@stigg/react-sdk bundles the JavaScript SDK — you do not need to install @stigg/js-client-sdk separately.

Installing the SDK

You have a few options for using the @stigg/react-sdk package in your project: From npm:

Retrieving the publishable key

In the Stigg app, go to Integrations > API keys. Copy the Publishable key of the relevant environment.

Getting started

First, you’ll need to wrap your application in a single StiggProvider component. that will provide the React Context to components that are placed inside your application:

Importing the styles

If you plan to use the widget components, add an import statement to include the bundled styles:

Setting the customer context

For in-app use (paywalls, customer portal, entitlement checks), pass the signed-in customer’s ID directly to StiggProvider. This is the recommended approach — you do not need to use the JavaScript SDK separately to set the customer ID:
If the customerId is not yet available when StiggProvider first renders (for example, it resolves after an async auth call), you can set it later via setCustomerId from the useStiggContext hook:

Rendering widgets

Pricing table

Allow customers to select the plan that that they’d like to subscribe to from your public pricing page or in-app paywall

Customer portal

Introduce self-service and drive in-app expansions using only a few lines of codes

Checkout

Easily accept payments without ever worrying about changes to your pricing model or migration to another billing provider

Custom hooks

The React SDK provides hooks that give you access to the Stigg object, entitlement checks, and helper methods for fetching data:

useStiggContext

Use the useStiggContext React hook to access Stigg’s JavaScript client easily from every component:

useBooleanEntitlement

The useBooleanEntitlement allows checking access for boolean entitlement:

useNumericEntitlement

The useNumericEntitlement allows checking access for numeric entitlement.
Use useNumericEntitlement for non-metered numeric features only. For metered features, use useMeteredEntitlement instead — calling useNumericEntitlement on a metered feature returns a FeatureTypeMismatch fallback in v9.0.0+.

useMeteredEntitlement

The useMeteredEntitlement allows checking access for metered entitlement:

useCreditEntitlement

The useCreditEntitlement hook returns the credit entitlement for a given credit-type feature. It reads directly from the SDK’s local cache — no extra API call, no rate-limit concerns. Available since @stigg/react-sdk v8.0.0.

useActiveSubscriptions

The useActiveSubscriptions return the active subscriptions list:

useCustomerPortal

The useCustomerPortal return the customer portal object:

usePaywall

The usePaywall return the paywall object:

Entitlement guard components

Entitlement guard components are useful in the cases where you need to wrap some part of the UI with an entitlement check and show a component in case the customer has no access to the feature:

BooleanEntitlementGuard

NumericEntitlementGuard

MeteredEntitlementGuard

Checkout widget callbacks

The Checkout widget supports user interaction callbacks that let you validate input, block navigation between steps, and show custom errors. All callbacks are optional and can be async.

Callback signatures

onBillableFeatureChange

Runs whenever a billable feature quantity is adjusted (e.g., seats, API calls). Return { errorMessage, disableNextStep } to surface inline validation and/or prevent advancing.

onAddonChange

Fires when an addon is added/removed or its quantity changes. Use it for addon-specific rules (compatibility, min/max, account policy).

onBeforeStepChange

Intercepts navigation between checkout steps (e.g., ADDONS to PAYMENT). Return false to block the step change and show your own messaging.

Customization options

The widgets that are included in this package include a default theme, which can be customized to match the appearance of your application.

Global theming

You can pass customization options such as theming and locale to StiggProvider component. Doing so will affect all Stigg widgets that are descendent to the provider.

Widget-specific customization

Each widget can be customized separately via the no-code widget designer in the Stigg app or using code. Widget-specific customization capabilities can be found under the dedicated page of each widget.

Refreshing the cache

Stigg’s SDK refreshes its cache of customer entitlements and usage data upon initialization (for example: when a page is refreshed), as well as periodically every 30 seconds. After performing an operation on the backend that can modify the customer entitlements or the usage of a feature (for example: updating subscriptions or reporting usage), it’s useful to immediately refresh the cache. To do so, call the below method:

Offline mode

During local development or testing, you might want to avoid making network requests to the Stigg API. To do this, you can run the React SDK in offline mode by enabling the offline option. When enabled, API key validation will always succeed, regardless of the key provided.
In offline mode, the React SDK respects the global fallback strategy, and entitlement evaluations are limited to the values defined as fallback entitlements.

Full SDK reference

React SDK reference

SDK changelog

React SDK changelog

Migrating to v9.0.0

Bumped @stigg/js-client-sdk to 4.0.0. The following breaking changes affect react-sdk consumers:

Migration from older SDK versions to v3.x

  • Removed CSS class names:
    • stigg-overview-subscriptions-list-layout
    • stigg-overview-subscriptions-list
    • stigg-billing-information-layout
    • stigg-billing-information-title
    • stigg-update-billing-button
  • Paywall textOverrides.price.paid paid text customization callback signature was changed: from:
    to: