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

231
Views
Play video when hover a card and show a default image when not hovering in react js

I have a list of videos. I only need to play the video when hover it. Other wise in need to show a default image that I have provided.

Lets say I have a coding like this. When I hover the card it need to play the video and when I am not hovering it need to show an image.

<Card>
     <video src={video} />
</Card>

I have used the npm package react-hover-video-player, but I don't to use an external package to do this. Is there a way to do this in React JS (Typescript)?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

How about make a new state for hovering and render conditionally ?

const [hover, setHover] = useState(false);

<Card
  onMouseEnter={(e:React.MouseEvent) => setHover(true)}
  onMouseLeave={(e:React.MouseEvent) => setHover(false)}
>
     {hover ? <video src={video} /> : <image src={image} />}
</Card>
about 4 years ago · Santiago Trujillo Report
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!