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

182
Vistas
Passing the right variable to a modal from a list of clickable items in React

I am using React for a website for an open garden scheme that I organise. I have a component in which you can look at a specific garden (garden.js) and its associated images. I present these images as smaller versions of the original.

I am making a modal (ImageModal.js) that starts when you click an image and shows normal size of that image. I got the modal running, but I don't understand how to get the right image data into that modal.

This is my (gutted) code so far:

----------------------
Garden.js
----------------------
export default function Garden() {

  const [openImageModal, setOpenImageModal] = useState(false);
  
  //Removed: fetch the garden and image objects from the database, imports, css styling, etc

  return (
    <div>
      <div>
        <h1>{garden.title}</h1>
        <div>
        {
          images.map((image) => (
            <img
              src={image.image}   //base64 encoded blob
              key={image.id}      //id of the image in the db
              alt={garden.title}
              onClick={() => { setOpenImageModal(true); }}
            ></img>
          ))
        }
      </div>
      {openImageModal && <ImageModal closeImageModal={setOpenImageModal} />}
    </div>
  );
}

----------------------
ImageModal.js
----------------------
export default function ImageModal({ closeImageModal }) {
  return (
    <div>
        <button onClick={() => closeImageModal(false)}>x</button>
    </div>
    <div>
        <img src={theProperImage}></img>
    </div>
  );
}

So my question is this: how do I get {image.image} from one of the images created by images.map into the modal so I can use it as (or in place of) {theProperImage}?

Hope I didn't forget anything to mention and thanks in advance!

about 4 years ago · Juan Pablo Isaza
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