import { useCallback, useRef } from "react"; import { useVideoPlayerState } from "../VideoContext"; export function VolumeControl() { const { videoState } = useVideoPlayerState(); const ref = useRef(null); const percentage = `${(videoState.volume * 100).toFixed(2)}%`; const handleClick = useCallback( (e: React.MouseEvent) => { if (!ref.current) return; const rect = ref.current.getBoundingClientRect(); const pos = (e.pageX - rect.left) / ref.current.offsetWidth; videoState.setVolume(pos); }, [videoState, ref] ); return (
); }