Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

150
Visualizações
How can i target a specific item from a list of array on Hover in React

I have a list of movies that I got from an API and I displayed them using the Map method, I'm trying to work on an option that when I hover on one of the cards I want to show the trailer of that specific movie in the place of the image. The problem that I face is when I hover, the video trailer is playing on all the cards, I would like to know how I can play that video on hover for a specific card.

My card component

const MovieCard = ({moviesList}) => {
    const [isHover, setIsHover] = useState(false);
    const trailer =
    "https://player.vimeo.com/external/371433846.sd.mp4?s=236da2f3c0fd273d2c6d9a064f3ae35579b2bbdf&profile_id=139&oauth2_token_id=57447761";
    return (
       moviesList.map((singleMovie)=> {
           const {id , title, poster_path, overview} = singleMovie;
            return (
               <article key={id} className="card"
                onMouseEnter= {()=> setIsHover(true)}
                onMouseLeave={()=> setIsHover(false)}>
                   <img src={`${ImgPath}` + poster_path} alt={title} className="image"/>
                   {isHover && <video src={trailer} autoPlay={true} loop></video>}
                   <div className="body-card">
                   <h1>{title}</h1>
                   <p>{`${overview.substring(0,200)}...`}</p>
                   </div>
                   
               </article>
            )
       })
          
    )
}

export default MovieCard

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Instead of boolean flag you can store the id and frankly, this functionality should go in the individual Card and you should render that Card in the loop.

Here's how you can do in the same implementation.

const MovieCard = ({moviesList}) => {
    const [selected, setSelected] = useState(null);
    const trailer =
    "https://player.vimeo.com/external/371433846.sd.mp4?s=236da2f3c0fd273d2c6d9a064f3ae35579b2bbdf&profile_id=139&oauth2_token_id=57447761";
    return (
       moviesList.map((singleMovie)=> {
           const {id , title, poster_path, overview} = singleMovie;
            return (
               <article key={id} className="card"
                onMouseEnter= {()=> setSelected(id)}
                onMouseLeave={()=> setSelected(null)}>
                   <img src={`${ImgPath}` + poster_path} alt={title} className="image"/>
                   {selected === id && <video src={trailer} autoPlay={true} loop></video>}
                   <div className="body-card">
                   <h1>{title}</h1>
                   <p>{`${overview.substring(0,200)}...`}</p>
                   </div>
                   
               </article>
            )
       })
          
    )
}

about 4 years ago · Juan Pablo Isaza Relatório

0

Your movieCard component not actually a movieCard component. Because you are taking the list of movie as a props so this is a movieCardList component. Instead doing that you can create a movieCard component that renders one movieCard element and inside of that component you can show the trail video in separatly.

    const movieCard =({movie} ) ={
  const handleTrailerShow = () =>{} 
return <div onSomeEvent={handleTrailerShow} >
  .... 
 </div>
}

And in your main component

const movieCardList =({movieList} ) ={
    return movieList.map(movie=>
<MovieCard movie={movie} />

 }
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda