Documentation Index
Fetch the complete documentation index at: https://docs.fanfare.io/llms.txt
Use this file to discover all available pages before exploring further.
React SDK Overview
The @waitify-io/fanfare-sdk-react package provides React-specific bindings for the Fanfare SDK, including hooks, context providers, and pre-built widget components.
Features
- FanfareProvider - Context provider for SDK instance
- Hooks - Reactive hooks for all SDK operations
- Widgets - Pre-built UI components (coming soon)
- Internationalization - Built-in i18n support
- TypeScript - Full type safety
Installation
npm install @waitify-io/fanfare-sdk-react @waitify-io/fanfare-sdk-core
# or
pnpm add @waitify-io/fanfare-sdk-react @waitify-io/fanfare-sdk-core
# or
yarn add @waitify-io/fanfare-sdk-react @waitify-io/fanfare-sdk-core
Quick Start
1. Wrap Your App
import { FanfareProvider } from "@waitify-io/fanfare-sdk-react";
function App() {
return (
<FanfareProvider organizationId="org_xxx" publishableKey="pk_live_xxx">
<YourApp />
</FanfareProvider>
);
}
2. Use Hooks
import { useQueue, useFanfareAuth } from "@waitify-io/fanfare-sdk-react";
function QueuePage() {
const { isAuthenticated, guest } = useFanfareAuth();
const { queue, status, position, enter, leave, isLoading, error } = useQueue("queue_123");
const handleEnter = async () => {
if (!isAuthenticated) {
await guest();
}
await enter();
};
if (isLoading) return <div>Loading...</div>;
if (error) return <div>Error: {error.message}</div>;
return (
<div>
<h1>{queue?.name}</h1>
{status?.status === "QUEUED" && (
<div>
<p>Your position: {position}</p>
<button onClick={leave}>Leave Queue</button>
</div>
)}
{status?.status === "ADMITTED" && (
<div>
<p>You are admitted!</p>
<a href={`/checkout?token=${status.admissionToken}`}>Go to Checkout</a>
</div>
)}
{!status && <button onClick={handleEnter}>Enter Queue</button>}
</div>
);
}
Exports
Provider
export { FanfareProvider } from "./provider";
export type { FanfareProviderProps } from "./provider";
Hooks
// Core hook
export { useFanfare } from "./hooks/use-fanfare";
// Auth hook
export { useFanfareAuth } from "./hooks/use-auth";
// Experience hooks
export { useQueue } from "./hooks/use-queue";
export { useDraw } from "./hooks/use-draw";
export { useAuction } from "./hooks/use-auction";
export { useWaitlist } from "./hooks/use-waitlist";
export { useTimedRelease } from "./hooks/use-timed-release";
// Journey hook
export { useExperienceJourney } from "./hooks/use-experience-journey";
export type {
ExperienceJourneyOptions,
ExperienceJourneyState,
ExperienceJourneyStatus,
UseExperienceJourneyOptions,
UseExperienceJourneyResult,
} from "./hooks/use-experience-journey";
i18n
export {
I18nProvider,
useTranslations,
useI18nContext,
type I18nProviderProps,
type Locale,
type TranslationMessages,
type PartialTranslationMessages,
} from "./i18n";
Theme
export { ThemeProvider, useThemeContext } from "./theme";
export type { ThemeProviderProps, ExperienceTheme } from "./theme";
Architecture
The React SDK wraps the Core SDK with React-specific patterns:
┌─────────────────────────────────────────────────────────────┐
│ Your React App │
├─────────────────────────────────────────────────────────────┤
│ FanfareProvider │
│ ├── I18nProvider (translations) │
│ ├── ThemeProvider (optional) │
│ └── FanfareContext (SDK instance) │
├─────────────────────────────────────────────────────────────┤
│ React Hooks │
│ ├── useFanfare() → SDK instance │
│ ├── useFanfareAuth() → Auth state + methods │
│ ├── useQueue() → Queue state + methods │
│ ├── useDraw() → Draw state + methods │
│ ├── useAuction() → Auction state + methods │
│ ├── useWaitlist() → Waitlist state + methods │
│ ├── useTimedRelease() → Timed release state + methods │
│ └── useExperienceJourney() → Journey orchestration │
├─────────────────────────────────────────────────────────────┤
│ Core SDK (@waitify-io/fanfare-sdk-core) │
└─────────────────────────────────────────────────────────────┘
Hook Pattern
All experience hooks follow a consistent pattern:
interface UseExperienceHook<TState, TActions> {
// State
isLoading: boolean;
error: Error | null;
status: ClientStatus;
// ... experience-specific state
// Actions
enter: (metadata?: Record<string, unknown>) => Promise<void>;
leave: () => Promise<void>;
// ... experience-specific actions
}
State Management
Hooks automatically:
- Subscribe to SDK events
- Update state reactively
- Clean up subscriptions on unmount
- Handle loading and error states
Event Subscriptions
Hooks subscribe to relevant SDK events:
function QueueComponent() {
const { position, status } = useQueue("queue_123");
// position updates automatically when queue:position-changed fires
// status updates automatically when queue:admitted fires
return <div>Position: {position}</div>;
}
TypeScript Support
The React SDK is fully typed:
import type {
FanfareProviderProps,
UseDrawClientStatus,
UseAuctionClientStatus,
UseTimedReleaseClientStatus,
UseWaitlistClientStatus,
ExperienceJourneyStatus,
} from "@waitify-io/fanfare-sdk-react";
Peer Dependencies
react >= 18.0.0
@waitify-io/fanfare-sdk-core >= 1.0.0
Next Steps