Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Property 'innerText' does not exist on type 'EventTarget' –TypeScript

i have a two column mega menu and i want when user hover a category, that category items to be displayed dynamic on second column .

i’m using typescript, the problem is when i wanna update the megaMenu state i get a red underline saying Property 'innerText' does not exist on type 'EventTarget'.
why is this happening ? i really appreciate some help.

  const [megaMenu, setMegaMenu] = useState("");

return (
            <Grid onMouseEnter={(e) => setMegaMenu(e.target.innerText)} >
             ....
             ....
             ....
             ....
             ....

            </Grid>
)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You could type cast event target to HTMLElement and access innerText over it

<Grid onMouseEnter={(e) => setMegaMenu((e.target as HTMLElement).innerText)} />
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading