Skip to main content
The useFeatureAccess hook lets you read a customer’s feature access and usage from your backend routes and use it directly in your UI.
Setup first: see the React integration guide.
const result = useFeatureAccess<MyFeatures>("priority_support", options?)

Parameters

featureKey
keyof MyFeatures
required
Feature key to read. Returns flattened fields for that feature plus isLoading, error, and refetch.
options.enabled
boolean
Enable or disable fetching. Defaults to true.
options.errorOnNotFound
boolean
When true, a 404 is surfaced as an error instead of returning null. Defaults to false.
options.swr
SWRConfiguration<MyFeatures | null, Error>
Optional SWR config for caching/revalidation behavior.

Returns

type
boolean (literal)
Feature type.
hasAccess
boolean
Whether the customer has access to the selected boolean feature.
isLoading
boolean
Whether data is currently loading.
error
Error | null
Error from the latest request.
refetch
() => Promise<void>
Manually revalidate feature access.

Examples

Single feature access

import { useFeatureAccess } from "priceos/react";
import type { MyFeatures } from "./priceos.types";

export function PrioritySupportButton() {
  const { hasAccess, isLoading } = useFeatureAccess<MyFeatures>("priority_support");

  const onClick = () => {
    if (!hasAccess) {
      // Show upgrade flow
      return;
    }
    // Open support flow
  };

  if (isLoading) return <div>Loading...</div>;
  return <button onClick={onClick}>Contact support</button>;
}

All feature access

import { useFeatureAccess } from "priceos/react";
import type { MyFeatures } from "./priceos.types";

export function PrioritySupportButton() {
  const { featureAccess, isLoading } = useFeatureAccess<MyFeatures>();
  const hasAccess = featureAccess?.priority_support?.hasAccess;

  const onClick = () => {
    if (!hasAccess) {
      // Show upgrade flow
      return;
    }
    // Open support flow
  };

  if (isLoading) return <div>Loading...</div>;
  return <button onClick={onClick}>Contact support</button>;
}

Displaying usage to user

import { useFeatureAccess } from "priceos/react";
import type { MyFeatures } from "./priceos.types";

export function UsageBadge() {
  const { hasAccess, usage, isUnlimited, limit } = useFeatureAccess<MyFeatures>("api_calls");

  if (!hasAccess) return <div>Upgrade required</div>;
  if (!usage) return <div>Usage tracking unavailable</div>;

  const label = isUnlimited ? `${usage.used} used` : `${usage.used} / ${limit}`;
  return <div>{label}</div>;
}

Determine if limit has been hit using PriceOS

import { useFeatureAccess } from "priceos/react";
import type { MyFeatures } from "./priceos.types";

export function CreateReportButton() {
  const { hasAccess, usage } = useFeatureAccess<MyFeatures>("api_calls");

  const onClick = () => {
    if (!hasAccess) return;
    if (usage?.hasReachedLimit) {
      // Block action: limit reached
      return;
    }
    // Continue action
  };

  return <button onClick={onClick}>Create report</button>;
}

Determine if limit has been hit using your own tracking

import { useFeatureAccess } from "priceos/react";
import type { MyFeatures } from "./priceos.types";

export function CreateReportButton({ currentUsage }: { currentUsage: number }) {
  const { hasAccess, limit, isUnlimited } = useFeatureAccess<MyFeatures>("api_calls");

  const onClick = () => {
    if (!hasAccess) return;
    if (!isUnlimited && typeof limit === "number" && currentUsage >= limit) {
      // Block action: limit reached (your own tracking)
      return;
    }
    // Continue action
  };

  return <button onClick={onClick}>Create report</button>;
}

Displaying bonuses to users

import { useFeatureAccess } from "priceos/react";
import type { MyFeatures } from "./priceos.types";

export function BonusUsageSummary() {
  const { usage } = useFeatureAccess<MyFeatures>("api_calls");

  if (!usage) return null;

  return (
    <div>
      <p>Bonus remaining: {usage.bonusRemaining}</p>
      <p>Bonus used: {usage.bonusUsed}</p>
    </div>
  );
}