I am using a library video js with react. For getting the watch time of a video. I am getting the watch time properly and Api is working fine but the issue is when I move to the next video or I change the page while watching video, the Api is called multiple times. I want it to make a request only one time. I am using the following code.
useEffect(()=>{
const videoElement = videoRef.current;
const player = playerRef.current = videojs(videoElement, options, () => {
console.log(player?.currentTime())
player.on("timeupdate", function ()
player.on('dispose', (e) => {
console.log(e)
e.preventDefault()
dispatch(getWatchTime({userId:user?._id,videoId:watch?._id,watchTime:player.currentTime()}))
})
});
})
},[])