FanfareProvider
TheFanfareProvider component initializes the Fanfare SDK and makes it available to all child components via React Context.
Basic Usage
Props
FanfareProviderProps
Required Props
| Prop | Type | Description |
|---|---|---|
organizationId | string | Your Fanfare organization ID |
publishableKey | string | Your publishable API key |
children | ReactNode | Child components |
Optional Props
| Prop | Type | Default | Description |
|---|---|---|---|
autoRestore | boolean | true | Restore session on mount |
autoResume | boolean | true | Resume operations after restore |
loadingComponent | ReactNode | null | Loading UI during initialization |
locale | Locale | "en" | Translation locale |
translations | PartialTranslationMessages | undefined | Custom translations |
environment | string | "production" | API environment |
debug | boolean | false | Enable debug logging |
Configuration Examples
With Loading State
With Custom Translations
With Locale
Development Configuration
Disable Auto-Restore
Initialization Lifecycle
The provider follows this lifecycle:- Mount - Provider renders
loadingComponent - Initialize - SDK is initialized with config
- Restore (if
autoRestore) - Session is restored from storage - Resume (if
autoResume) - Active operations are resumed - Ready - Children are rendered with SDK context
Error Handling
If initialization fails, the provider logs an error and rendersnull:
Environment Variables
Configure the provider with environment variables:Multiple Providers
For multi-organization scenarios, use separate providers:Cleanup
The provider automatically cleans up the SDK when unmounted:- SDK
destroy()is called - All polling is stopped
- Event subscriptions are cleaned up
- Pending beacon events are flushed
TypeScript
Next Steps
- Context Hook - Access the SDK instance
- Hooks Overview - Available hooks
- Internationalization - Translation system