woocommerce-paypal-payments/modules/ppcp-axo-block/resources/js/components/FastlaneWatermark.js

45 lines
970 B
JavaScript
Raw Normal View History

import { useEffect, useRef } from '@wordpress/element';
2024-09-05 21:17:36 +02:00
export const FastlaneWatermark = ( {
fastlaneSdk,
name = 'fastlane-watermark-container',
includeAdditionalInfo = true,
} ) => {
const containerRef = useRef( null );
const watermarkRef = useRef( null );
2024-09-05 21:17:36 +02:00
useEffect( () => {
const renderWatermark = async () => {
if ( ! containerRef.current ) {
return;
}
// Clear the container
containerRef.current.innerHTML = '';
try {
const watermark = await fastlaneSdk.FastlaneWatermarkComponent(
{
includeAdditionalInfo,
}
);
watermarkRef.current = watermark;
watermark.render( `#${ name }` );
} catch ( error ) {
console.error( 'Error rendering watermark:', error );
}
};
renderWatermark();
return () => {
if ( containerRef.current ) {
containerRef.current.innerHTML = '';
}
};
}, [ fastlaneSdk, name, includeAdditionalInfo ] );
return <div id={ name } ref={ containerRef } />;
2024-09-05 21:17:36 +02:00
};