A
A
Alex Ozerov2021-08-16 15:58:50
typescript
Alex Ozerov, 2021-08-16 15:58:50

What type to specify for Event?

there is an input with attributes name & value; I write a handler in which I want to pull out these values, but I get:


Property 'name' does not exist on type 'EventTarget'


const handleChange = (event: React.FormEvent) => {
        console.log(event.target.name)
    }


How to correctly determine the type of event?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
SANTA2112, 2021-08-16
@alex_vma

const handleChange = (event: React.FormEvent<HTMLFormElement>) => {
  console.log(event.currentTarget.name)
}

S
Stas Khitrich, 2021-08-16
@Snova_s_vami

Just tried Event?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question