The SDK maintains persistent connections for real-time updates. Avoid creating multiple client instances.
// Good: Single client instanceconst client = new FanfareClient({ publishableKey: "pk_live_..." });// Use the same client throughout your applicationexport { client };
// Bad: Multiple client instancesfunction enterExperience(id: string) { // Creates new connections each time const client = new FanfareClient({ publishableKey: "pk_live_..." }); return client.experiences.enter(id);}
The API returns rate limit headers to help you optimize request patterns.
// Rate limit headers returned by the API// X-RateLimit-Limit: Maximum requests per window// X-RateLimit-Remaining: Remaining requests in window// Retry-After: Seconds to wait if rate limited// SDK handles rate limits automatically with exponential backoff// For custom implementations, respect the Retry-After header
The SDK maintains session state internally. Access it without additional API calls.
// Get current session state without API callconst session = client.experiences.getActiveSession();const isInQueue = client.queues.isInQueue(queueId);const position = client.queues.getPosition(queueId);
// Good: Subscribe to specific eventsclient.on("queue:position-updated", handlePositionUpdate);client.on("queue:access-granted", handleAccessGranted);// Clean up when component unmountsreturn () => { client.off("queue:position-updated", handlePositionUpdate); client.off("queue:access-granted", handleAccessGranted);};
// Good: Import specific hooksimport { useExperienceJourney } from "@fanfare/sdk-react";// Avoid: Importing entire package if using only specific featuresimport * as Fanfare from "@fanfare/sdk-react";