@canopyconnect/components
v1.0.0-beta.1
Published
Canopy Connect Components loading utility
Maintainers
Readme
@canopyconnect/components
A lightweight utility for dynamically loading Canopy Connect Components in your application.
Installation
npm install @canopyconnect/componentsUsage
Basic Usage
import { loadCanopyConnectComponents } from '@canopyconnect/components';
// Load the components library
const CanopyConnectComponents = await loadCanopyConnectComponents();
// Now use the CanopyConnectComponents class to create forms
// See https://docs.usecanopy.com/reference/components-getting-started for complete usage examplesError Handling
The loadCanopyConnectComponents() function returns a Promise that may reject if:
- The script fails to load from the CDN
- The script loads but doesn't expose the expected API
try {
const CanopyConnectComponents = await loadCanopyConnectComponents();
// Use components...
} catch (error) {
console.error('Failed to load Canopy Connect Components:', error);
}Retry Logic
The loader automatically handles retries. If a load attempt fails, subsequent calls to loadCanopyConnectComponents() will create a fresh request rather than returning the failed Promise.
// First attempt fails
try {
await loadCanopyConnectComponents();
} catch (error) {
console.log('First attempt failed');
}
// Second attempt creates a new request
try {
const components = await loadCanopyConnectComponents();
console.log('Second attempt succeeded');
} catch (error) {
console.log('Second attempt also failed');
}TypeScript Support
This package includes full TypeScript definitions:
import { loadCanopyConnectComponents, type CanopyConnectComponents } from '@canopyconnect/components';
const components: CanopyConnectComponents = await loadCanopyConnectComponents();API Reference
loadCanopyConnectComponents()
Returns a Promise that resolves to the CanopyConnectComponents class.
- Returns:
Promise<CanopyConnectComponents> - Throws:
Errorif the script fails to load or initialize
See the full documentation for complete API details.
