Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

192
Vistas
How do I show data on one card when hovering and not on all?

Okay there is definitely a quick solution for this I just can't figure out.

Just a description of what I am trying to do:

Whenever I hover over a certain card, I would like to see the description of that item and only that item. But instead what's obviously happening, as you can see from my code, is every single cards description is showing.

I rewrote a simpler version of the code by taking out any unnecessary pieces. Everything is imported correctly, styling and classNames were removed as well.

export function Items() {
    const [items, setItems] = useState([])
    const [isHovering, setIsHovering] = useState(false)

    useEffect(() => {
        setItems(Data)
    }, [])
    
    function handleMouseOver() {
        setIsHovering(true)
    }
    function handleMouseOut() {
        setIsHovering(false)
    }

    return(
        <div>
            {items.map(item => {
                return(
                    <Card onMouseOver={handleMouseOver} onMouseOut={handleMouseOut} key={item.id}>
                        {isHovering ? 
                            <Card.Body>
                                <p>{item.item_description}</p>
                            </Card.Body>
                        :
                            <Card.Body>
                            </Card.Body>
                        }
                        <Card.Footer>

                        </Card.Footer>
                    </Card>
                )
            })}
        </div>
    )
}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

As far as I can see you don't need to put this logic into parent component, and also it makes everything more complex, since it's hard to manage hovering. I would create new chlid component and manage this state out there internally.

export function Item({item}) {
  const [isHovering, setIsHovering] = useState(false);

  useEffect(() => {
    setItems(Data);
  }, []);

  function handleMouseOver() {
    setIsHovering(true);
  }
  function handleMouseOut() {
    setIsHovering(false);
  }

  return (
    <Card onMouseOver={handleMouseOver} onMouseOut={handleMouseOut}>
      {isHovering ? (
        <Card.Body>
          <p>{item.item_description}</p>
        </Card.Body>
      ) : (
        <Card.Body></Card.Body>
      )}
      <Card.Footer></Card.Footer>
    </Card>
  );
}

export function Items() {
  const [items, setItems] = useState([]);

  return (
    <div>
      {items.map(item => (
        <Item key={item.id} item={item} />
      ))}
    </div>
  );
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

Your "isHovering" state should also be an array, where you store the hover state for every card. Then on hover set "isHovering" to true only for the right card.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda