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