ConnectHub Web SDK v3.2.0
The official ConnectHub JavaScript SDK for building modern, interactive social features directly into your web applications. Supports React, Vue, Svelte, and vanilla JS.
You need a ConnectHub Developer account and an active project with API credentials. Generate your keys in the Dashboard → Settings → API Keys.
Installation
Install the SDK via your preferred package manager:
CDN Usage: For quick prototypes without a build step:
Quick Start
Initialize the SDK in your application entry point:
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
clientId |
string |
Required | Your unique project identifier from the dashboard. |
environment |
string |
'sandbox' |
Target environment. Use 'production' for live apps. |
region |
string |
'auto' |
API region endpoint. 'auto' detects closest edge. |
timeout |
number |
10000 |
Request timeout in milliseconds. |
retryAttempts |
number |
3 |
Automatic retry count for failed network requests. |
Authentication
The SDK provides secure, OAuth2-compliant authentication flows with automatic token refresh:
Never expose your clientSecret in client-side code. The Web SDK uses PKCE flow and never requires server-side secrets for authentication.
Feed & Content
Render personalized feeds with infinite scroll and real-time updates:
Event System
The SDK uses a robust EventEmitter pattern for lifecycle and state changes:
Best Practices
Use hub.ui.render() for virtualized lists when displaying >100 items. Enable cache: true in fetch calls to reduce network overhead. Always wrap SDK calls in error boundaries.
- Initialize the SDK once per application lifecycle
- Use environment variables for
clientId - Implement exponential backoff for rate-limited endpoints
- Cache feed data locally using IndexedDB for offline support
FAQ & Troubleshooting
Why am I getting 401 Unauthorized?
This usually means your session token has expired or was invalidated. Call hub.auth.refresh() or trigger a re-login. Check that your redirectUri matches the one configured in the dashboard.
How do I debug SDK network requests?
Set debug: true during initialization. The SDK will log all outbound requests, responses, and state changes to the browser console with [ConnectHub] prefixes.
Does the SDK support SSR/Next.js?
Yes, but the SDK must only be instantiated on the client side. Wrap initialization in useEffect or if (typeof window !== 'undefined') guards to avoid hydration mismatches.