Skip to content

Commit

Permalink
useCallback instead of useEffect for PreviewLiveView
Browse files Browse the repository at this point in the history
  • Loading branch information
charlielee committed Nov 27, 2023
1 parent f74bd9b commit 35290c0
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { useEffect, useRef } from "react";
import { useCallback } from "react";
import "./PreviewLiveView.css";

interface PreviewLiveViewProps {
stream: MediaStream | undefined;
}

const PreviewLiveView = ({ stream }: PreviewLiveViewProps): JSX.Element => {
const videoRef = useRef<HTMLVideoElement>(null);

useEffect(() => {
const video = videoRef.current;
if (video) {
video.srcObject = stream ?? null;
}
}, [stream]);
const videoRef = useCallback(
(video: HTMLVideoElement | null) => {
if (video) {
video.srcObject = stream ?? null;
}
},
[stream]
);

return <video className="preview-live-view" autoPlay ref={videoRef}></video>;
};
Expand Down

0 comments on commit 35290c0

Please sign in to comment.