I am developing a react app with a firebase backend. I loop through firestore collection and display the images from that collection.
const getdata = Object.entries(mydata).map(pair => { const key = pair[0] const value = pair[1] return ( <div className='image"> <img src={value} id={key} onclick={showpop} /> </div> ) }
When the image is clicked, it should show a pop up, and I am doing that like so:
function showpop(){ var img = document.getElementById(//get value of the id here from the key); img.onclick = function(){ //show popup here } }
I have tried with getElementById(key), getElementById(props.key), but they all give me errors.
onclick={()=>{showpop(value)}}, just like my answer