Try this. For making third-party libs control some element inside your React component you need to bind them to React lifecycle methods (for a function component it would be useEffect
). Supposing you are using Create React App.
First, add the script import in your public/index.html
file.
<script src="https://product-gallery.cloudinary.com/all.js" type="text/javascript"></script>
With function components would be something like this:
const FullProduct = () => {
const cloudnaryGalleryRef = useRef(null);
useEffect(() => {
if (!cloudnaryGalleryRef.current) {
cloudnaryGalleryRef.current = cloudinary.galleryWidget({
container: '#my-gallery',
cloudName: 'demo',
mediaAssets: [
{ tag: 'electric_car_product_gallery_demo' },
{ tag: 'electric_car_product_gallery_demo', mediaType: 'video' },
{ tag: 'electric_car_360_product_gallery_demo', mediaType: 'spin' }
]
});
}
}, []);
return <div id="my-gallery" />;
};
And then you can use cloudnaryGalleryRef.current
to access all the methods the lib gives you.