Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

161
Views
React Lifecycle Video

I was creating this React component and I was astonished by the fact that when I clicked on the video I got false on console immediatelly after the video started. I was expecting that it would print true when the video started, and false when it finished. I think I'm confusing the lifecycle of this particular component, and I would be really grateful if someone could clarify this to me.

const Video = ({src, type, index, isAutoPlay}) => {
  
  const [play, setPlay] = useState(isAutoPlay)

  const playRef = useRef();

  useEffect(() => {
    if (play && playRef.current) {
      playRef.current.play();
    }
    return () => setPlay(false)
  }, [play]);
  return (
    <>
      <video 
       className="slide" 
       ref={playRef} 
       onClick={() => {
                setPlay(true); 
                console.log(play);}}>
        <source src={src} type={type} key={index}/>
        Your browser does not support the video tag.
      </video>
    </>
  )
}

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!