improvement: use useCallback instead of setting ref auto-magically

This commit is contained in:
JohnMark Sill 2022-06-02 14:39:53 -05:00 committed by Blake Blackshear
parent fa95a041dd
commit 37011c2fda

View File

@ -41,11 +41,16 @@ export const HistoryVideo = ({
videoUrl: '', videoUrl: '',
}); });
useEffect(() => { const videoCallback = useCallback(
if (posterLoaded && videoRef.current) { (domNode: any) => {
setVideoHeight(videoRef.current?.offsetHeight); videoRef.current = domNode;
}
}, [posterLoaded, videoRef.current]); if (posterLoaded) {
setVideoHeight(videoRef.current?.offsetHeight);
}
},
[posterLoaded]
);
useEffect(() => { useEffect(() => {
const idExists = !isNullOrUndefined(id); const idExists = !isNullOrUndefined(id);
@ -123,7 +128,7 @@ export const HistoryVideo = ({
const { posterUrl, videoUrl } = videoProperties; const { posterUrl, videoUrl } = videoProperties;
return ( return (
<video <video
ref={videoRef} ref={videoCallback}
key={posterUrl} key={posterUrl}
onTimeUpdate={onTimeUpdateHandler} onTimeUpdate={onTimeUpdateHandler}
onPause={onPause} onPause={onPause}