From 49a2fe0c26fb2d70e73e998918e38aec03446d59 Mon Sep 17 00:00:00 2001 From: Sahil Silare Date: Thu, 3 Oct 2024 23:26:43 +0530 Subject: [PATCH 1/2] feat: added unique id generation using React's `useId()` hook --- .../src/components/CldVideoPlayer/CldVideoPlayer.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/next-cloudinary/src/components/CldVideoPlayer/CldVideoPlayer.tsx b/next-cloudinary/src/components/CldVideoPlayer/CldVideoPlayer.tsx index 8f7f0870..49c12965 100644 --- a/next-cloudinary/src/components/CldVideoPlayer/CldVideoPlayer.tsx +++ b/next-cloudinary/src/components/CldVideoPlayer/CldVideoPlayer.tsx @@ -1,4 +1,4 @@ -import React, {useRef, MutableRefObject, useEffect} from 'react'; +import React, {useRef, MutableRefObject, useEffect, useId} from 'react'; import Script from 'next/script'; import Head from 'next/head'; import { CloudinaryVideoPlayer } from '@cloudinary-util/types'; @@ -28,6 +28,7 @@ const CldVideoPlayer = (props: CldVideoPlayerProps) => { width, } = props as CldVideoPlayerProps; + const uniqueId = useId(); const cloudinaryConfig = getCloudinaryConfig(config); const playerOptions = getVideoPlayerOptions(props, cloudinaryConfig); @@ -46,7 +47,7 @@ const CldVideoPlayer = (props: CldVideoPlayerProps) => { const defaultPlayerRef = useRef()as MutableRefObject; const playerRef = props.playerRef || defaultPlayerRef; - const playerId = id || `player-${publicId.replace('/', '-')}`; + const playerId = id || `player-${uniqueId}`; let playerClassName = 'cld-video-player cld-fluid'; if ( className ) { @@ -137,7 +138,7 @@ const CldVideoPlayer = (props: CldVideoPlayerProps) => { height={height} />