how to play/pause video in React without external library?

后端 未结 5 1014

I have a video tag () in my webpage, and a \"play/pause\" button that when the user clicks on it, the video starts/stops playing . How can I do so in react if I\'m not allowed t

5条回答
  •  梦如初夏
    2021-02-14 00:32

    Updated example for React Function Components:

    import React, { useRef} from 'react'
    
    function myComponent(props) {
      const vidRef = useRef(null);
      const handlePlayVideo = () => {
        vidRef.current.play();
      }
      return (
        
      )
    }
    
    
    

提交回复
热议问题