I am trying to capture events from an html <video/> tag. I have set a ref to it, and using a useEffect am trying to capture the events. However, i beleive I am not handling the ref correctly and am not capturing any of the events. Can someone spot my error?
const elementRef = useRef(null);
function handleEvent(event) {
console.log(`${event.type}\n`);
}
useEffect(() => {
return () => {
elementRef.addEventListener('loadstart', handleEvent);
elementRef.addEventListener('progress', handleEvent);
elementRef.addEventListener('canplay', handleEvent);
elementRef.addEventListener('canplaythrough', handleEvent);
elementRef.addEventListener('ended', handleEvent);
elementRef.addEventListener('pause', handleEvent);
elementRef.addEventListener('play', handleEvent);
elementRef.addEventListener('playing', handleEvent);
elementRef.addEventListener('ratechange', handleEvent);
elementRef.addEventListener('seeking', handleEvent);
elementRef.addEventListener('stalled', handleEvent);
};
}, [elementRef]);
in my return i have <video controls src={FirstVid} poster={Poster} width="620" ref={(el) => (elementRef.current = el)}/>