Skip to content

🎥 Make videos programmatically with React

add dependencies to useImperativeHandle

Jonny Burger6cb2cc4fae2f
diff --git a/packages/cli/src/editor/components/NewComposition/RemInput.tsx b/packages/cli/src/editor/components/NewComposition/RemInput.tsx
index 7b1fc4204f..7a56b0d43d 100644
--- a/packages/cli/src/editor/components/NewComposition/RemInput.tsx
+++ b/packages/cli/src/editor/components/NewComposition/RemInput.tsx
@@ -50,9 +50,13 @@ const RemInputForwardRef: React.ForwardRefRenderFunction<
};
}, [isFocused, isHovered, props.style]);
- useImperativeHandle(ref, () => {
- return inputRef.current as HTMLInputElement;
- });
+ useImperativeHandle(
+ ref,
+ () => {
+ return inputRef.current as HTMLInputElement;
+ },
+ []
+ );
useEffect(() => {
if (!inputRef.current) {
diff --git a/packages/cli/src/editor/components/Notifications/NotificationCenter.tsx b/packages/cli/src/editor/components/Notifications/NotificationCenter.tsx
index 6d6649329d..10079562ad 100644
--- a/packages/cli/src/editor/components/Notifications/NotificationCenter.tsx
+++ b/packages/cli/src/editor/components/Notifications/NotificationCenter.tsx
@@ -46,11 +46,15 @@ export const NotificationCenter: React.FC = () => {
});
}, []);
- useImperativeHandle(notificationCenter, () => {
- return {
- addNotification,
- };
- });
+ useImperativeHandle(
+ notificationCenter,
+ () => {
+ return {
+ addNotification,
+ };
+ },
+ [addNotification]
+ );
return (
<div style={container}>
diff --git a/packages/cli/src/editor/components/Timeline/Timeline.tsx b/packages/cli/src/editor/components/Timeline/Timeline.tsx
index 9373c9c824..5e20c690f5 100644
--- a/packages/cli/src/editor/components/Timeline/Timeline.tsx
+++ b/packages/cli/src/editor/components/Timeline/Timeline.tsx
@@ -60,22 +60,26 @@ export const Timeline: React.FC = () => {
});
}, [sequences, videoConfig]);
- useImperativeHandle(timelineRef, () => {
- return {
- expandAll: () => {
- dispatch({
- type: 'expand-all',
- allHashes: timeline.map((t) => t.hash),
- });
- },
- collapseAll: () => {
- dispatch({
- type: 'collapse-all',
- allHashes: timeline.map((t) => t.hash),
- });
- },
- };
- });
+ useImperativeHandle(
+ timelineRef,
+ () => {
+ return {
+ expandAll: () => {
+ dispatch({
+ type: 'expand-all',
+ allHashes: timeline.map((t) => t.hash),
+ });
+ },
+ collapseAll: () => {
+ dispatch({
+ type: 'collapse-all',
+ allHashes: timeline.map((t) => t.hash),
+ });
+ },
+ };
+ },
+ [timeline]
+ );
const withoutHidden = useMemo(() => {
return timeline.filter((t) => !isTrackHidden(t, timeline, state));
diff --git a/packages/cli/src/editor/components/Timeline/TimelineSlider.tsx b/packages/cli/src/editor/components/Timeline/TimelineSlider.tsx
index 640256bf46..8a66563015 100644
--- a/packages/cli/src/editor/components/Timeline/TimelineSlider.tsx
+++ b/packages/cli/src/editor/components/Timeline/TimelineSlider.tsx
@@ -45,22 +45,26 @@ export const TimelineSlider: React.FC = () => {
};
}, [timelinePosition, get]);
- useImperativeHandle(redrawTimelineSliderFast, () => {
- return {
- draw: (frame, width?: number) => {
- const {current} = ref;
- if (!current) {
- throw new Error('unexpectedly did not have ref to timelineslider');
- }
+ useImperativeHandle(
+ redrawTimelineSliderFast,
+ () => {
+ return {
+ draw: (frame, width?: number) => {
+ const {current} = ref;
+ if (!current) {
+ throw new Error('unexpectedly did not have ref to timelineslider');
+ }
- current.style.transform = `translateX(${getXPositionOfItemInTimelineImperatively(
- frame,
- getCurrentDuration(),
- width ?? (sliderAreaRef.current?.clientWidth as number) ?? 0
- )}px)`;
- },
- };
- });
+ current.style.transform = `translateX(${getXPositionOfItemInTimelineImperatively(
+ frame,
+ getCurrentDuration(),
+ width ?? (sliderAreaRef.current?.clientWidth as number) ?? 0
+ )}px)`;
+ },
+ };
+ },
+ []
+ );
useEffect(() => {
const currentRef = ref.current;
diff --git a/packages/cli/src/editor/components/TimelineInOutToggle.tsx b/packages/cli/src/editor/components/TimelineInOutToggle.tsx
index 68d606db73..2c1712575e 100644
--- a/packages/cli/src/editor/components/TimelineInOutToggle.tsx
+++ b/packages/cli/src/editor/components/TimelineInOutToggle.tsx
@@ -263,19 +263,23 @@ export const TimelineInOutPointToggle: React.FC = () => {
}
}, [onInOutClear, inFrame, videoConfig]);
- useImperativeHandle(inOutHandles, () => {
- return {
- clearMarks: onInOutClear,
- inMarkClick: onInMark,
- outMarkClick: onOutMark,
- setMarks: ([newInFrame, newOutFrame]) => {
- setInAndOutFrames({
- inFrame: newInFrame,
- outFrame: newOutFrame,
- });
- },
- };
- });
+ useImperativeHandle(
+ inOutHandles,
+ () => {
+ return {
+ clearMarks: onInOutClear,
+ inMarkClick: onInMark,
+ outMarkClick: onOutMark,
+ setMarks: ([newInFrame, newOutFrame]) => {
+ setInAndOutFrames({
+ inFrame: newInFrame,
+ outFrame: newOutFrame,
+ });
+ },
+ };
+ },
+ [onInMark, onInOutClear, onOutMark, setInAndOutFrames]
+ );
if (!videoConfig) {
return null;
diff --git a/packages/core/src/Img.tsx b/packages/core/src/Img.tsx
index a35e3d6899..1a1b8e67fc 100644
--- a/packages/core/src/Img.tsx
+++ b/packages/core/src/Img.tsx
@@ -18,9 +18,13 @@ const ImgRefForwarding: React.ForwardRefRenderFunction<
> = ({onError, src, ...props}, ref) => {
const imageRef = useRef<HTMLImageElement>(null);
- useImperativeHandle(ref, () => {
- return imageRef.current as HTMLImageElement;
- });
+ useImperativeHandle(
+ ref,
+ () => {
+ return imageRef.current as HTMLImageElement;
+ },
+ []
+ );
const actualSrc = usePreload(src as string);
diff --git a/packages/core/src/audio/AudioForDevelopment.tsx b/packages/core/src/audio/AudioForDevelopment.tsx
index 9f02f7de1b..8fc1b3d99e 100644
--- a/packages/core/src/audio/AudioForDevelopment.tsx
+++ b/packages/core/src/audio/AudioForDevelopment.tsx
@@ -106,9 +106,13 @@ const AudioForDevelopmentForwardRefFunction: React.ForwardRefRenderFunction<
onlyWarnForMediaSeekingError: false,
});
- useImperativeHandle(ref, () => {
- return audioRef.current as HTMLAudioElement;
- });
+ useImperativeHandle(
+ ref,
+ () => {
+ return audioRef.current as HTMLAudioElement;
+ },
+ [audioRef]
+ );
if (initialShouldPreMountAudioElements) {
return null;
diff --git a/packages/core/src/audio/AudioForRendering.tsx b/packages/core/src/audio/AudioForRendering.tsx
index 8089f615da..7ef200a1a0 100644
--- a/packages/core/src/audio/AudioForRendering.tsx
+++ b/packages/core/src/audio/AudioForRendering.tsx
@@ -47,9 +47,13 @@ const AudioForRenderingRefForwardingFunction: React.ForwardRefRenderFunction<
mediaVolume: 1,
});
- useImperativeHandle(ref, () => {
- return audioRef.current as HTMLVideoElement;
- });
+ useImperativeHandle(
+ ref,
+ () => {
+ return audioRef.current as HTMLVideoElement;
+ },
+ []
+ );
useEffect(() => {
if (!props.src) {
diff --git a/packages/core/src/prefetch-state.tsx b/packages/core/src/prefetch-state.tsx
index 7786e9d41d..748fb42f16 100644
--- a/packages/core/src/prefetch-state.tsx
+++ b/packages/core/src/prefetch-state.tsx
@@ -32,11 +32,15 @@ export const PrefetchProvider: React.FC<{
};
}, [preloads]);
- useImperativeHandle(preloadRef, () => {
- return {
- setPreloads,
- };
- });
+ useImperativeHandle(
+ preloadRef,
+ () => {
+ return {
+ setPreloads,
+ };
+ },
+ []
+ );
return (
<PreloadContext.Provider value={value}>{children}</PreloadContext.Provider>
diff --git a/packages/core/src/video/VideoForDevelopment.tsx b/packages/core/src/video/VideoForDevelopment.tsx
index c383756148..224e6b2cea 100644
--- a/packages/core/src/video/VideoForDevelopment.tsx
+++ b/packages/core/src/video/VideoForDevelopment.tsx
@@ -64,9 +64,13 @@ const VideoForDevelopmentRefForwardingFunction: React.ForwardRefRenderFunction<
const actualSrc = usePreload(src as string);
- useImperativeHandle(ref, () => {
- return videoRef.current as HTMLVideoElement;
- });
+ useImperativeHandle(
+ ref,
+ () => {
+ return videoRef.current as HTMLVideoElement;
+ },
+ []
+ );
useEffect(() => {
const {current} = videoRef;
diff --git a/packages/core/src/video/VideoForRendering.tsx b/packages/core/src/video/VideoForRendering.tsx
index d7fc4ee0eb..cc99e26567 100644
--- a/packages/core/src/video/VideoForRendering.tsx
+++ b/packages/core/src/video/VideoForRendering.tsx
@@ -105,9 +105,13 @@ const VideoForRenderingForwardFunction: React.ForwardRefRenderFunction<
playbackRate,
]);
- useImperativeHandle(ref, () => {
- return videoRef.current as HTMLVideoElement;
- });
+ useImperativeHandle(
+ ref,
+ () => {
+ return videoRef.current as HTMLVideoElement;
+ },
+ []
+ );
useEffect(() => {
if (!window.remotion_videoEnabled) {
diff --git a/packages/docs/src/components/MuxVideo.tsx b/packages/docs/src/components/MuxVideo.tsx
index 1726a3c039..4443018dc8 100644
--- a/packages/docs/src/components/MuxVideo.tsx
+++ b/packages/docs/src/components/MuxVideo.tsx
@@ -22,7 +22,7 @@ const MuxVideoForward: React.ForwardRefRenderFunction<
const videoRef = useRef<HTMLVideoElement>(null);
const vidUrl = getVideoToPlayUrl(muxId);
- useImperativeHandle(ref, () => videoRef.current);
+ useImperativeHandle(ref, () => videoRef.current, []);
useEffect(() => {
let hls: Hls;
diff --git a/packages/gif/src/canvas.tsx b/packages/gif/src/canvas.tsx
index f52c414790..7eb9dd51ec 100644
--- a/packages/gif/src/canvas.tsx
+++ b/packages/gif/src/canvas.tsx
@@ -105,9 +105,13 @@ export const Canvas = forwardRef(
const size = useElementSize(canvasRef);
- useImperativeHandle(ref, () => {
- return canvasRef.current as HTMLCanvasElement;
- });
+ useImperativeHandle(
+ ref,
+ () => {
+ return canvasRef.current as HTMLCanvasElement;
+ },
+ []
+ );
useEffect(() => {
if (!size) {
diff --git a/packages/player/src/Player.tsx b/packages/player/src/Player.tsx
index c16f935472..386b23bd58 100644
--- a/packages/player/src/Player.tsx
+++ b/packages/player/src/Player.tsx
@@ -275,7 +275,7 @@ export const PlayerFn = <T,>(
persistVolume(vol);
}, []);
- useImperativeHandle(ref, () => rootRef.current as PlayerRef);
+ useImperativeHandle(ref, () => rootRef.current as PlayerRef, []);
const timelineContextValue = useMemo((): TimelineContextValue & {
shouldRegisterSequences: boolean;