React
Integrate DotPassport widgets into React applications.
Installation
npm install @dotpassport/sdkBasic Component
Create a reusable widget component:
import { useEffect, useRef } from 'react';
import { createWidget, type WidgetConfig } from '@dotpassport/sdk';
export function DotPassportWidget(config: WidgetConfig) {
const ref = useRef<HTMLDivElement>(null);
const widgetRef = useRef<any>();
useEffect(() => {
if (ref.current && !widgetRef.current) {
widgetRef.current = createWidget(config);
widgetRef.current.mount(ref.current);
}
return () => widgetRef.current?.destroy();
}, []);
useEffect(() => {
widgetRef.current?.update(config);
}, [config]);
return <div ref={ref} />;
}Usage
Dynamic Updates
Multiple Widgets
Next Steps
Last updated
