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

134
Vistas
React / NextJS - onClick targets all mapped items - how do i target just one?

Couldn't figure out a better way to word the problem i have, sorry if this gets asked often.

Code is like this:

  const [isFlipped, setFlipped] = useState(false);

  const flip = () => {
    if (!isFlipped) {
      setFlipped(true);
    } else {
      setFlipped(false);
    }
  };
return(
data.map((product) => (
  <div 
    onClick={()=> flip()}
    animate={isFlipped && { rotateY: 180 }}
>
    <p>{product.name}</p>
    <p>{product.info}</p>
  </div>
 ));
)

i want the flip() function to work only on the div that gets clicked, however currently it affects every mapped div.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Edit (After seeing the flip function): You should make this a seperate component so each child has it's own isFlipped State. And then map and create the components with the product as a prop.

Add a key to the div in the map to add uniqueness.

data.map((product, key) => (
  <div key={key} onClick={()=> flip()}>
    <p>{product.name}</p>
    <p>{product.info}</p>
  </div>
 ));

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