Solid1
Solid1

Reputation: 853

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>
)

Upvotes: 1

Views: 1655

Answers (1)

Pratik Wadekar
Pratik Wadekar

Reputation: 1274

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

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

Upvotes: 1

Related Questions