The current PlayVideoWithButton
component renders a video player with a play/pause button. However, the implementation is incomplete and has the following issues:
isPlaying
state is not being used effectively.Your goal is to modify the PlayVideoWithButton
component to create a fully functional video player with the following features:
isPlaying
state should accurately reflect whether the video is currently playing or paused.useRef
hook to interact with the video element directly.import { useState, useRef } from 'react'; import './play-pause-video.css' export default function PlayVideoWithButton() { const isPlaying = false; const [error, setError] = useState(null); if(error) { return <div data-testid="error-message">{error}</div> } return ( <div className="video-container"> <button data-testid="play-pause-button" className="play-button" > {isPlaying ? 'Pause' : 'Play'} </button> <video data-testid="video-player" className="video-player" controls onError={() => setError("Something went wrong loading the video!")} > <source src="https://sample-videos.com/video321/mp4/720/big_buck_bunny_720p_2mb.mp4" type="video/mp4" /> </video> </div> ) }
Tests