My issue is that e.target
doesn't have the classList
property when event handler for click
is executing. Here is my code:
import React from 'react'
interface props{
imageUrl: string,
setSelectdImage : (value: React.SetStateAction<string>) => void
}
const Modal:React.FC<props> = ({imageUrl,setSelectdImage}) => {
return (
<div className='fixed top-0 left-0 w-full h-full bg-halfTransparent' onClick={ (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
if(e.target.classList){ // here is issue
setSelectdImage('')
}
}}>
<img className="block max-w-4xl max-h-6 mt-24 mx-auto shadow-md" src={imageUrl} alt="large image"/>
</div>
)
}
export default Modal
thanks
from Typescript 3.2.4 you can retrieve classList by this way:
(e.target as Element).classList
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With