React TypeScript Input Paste Event

Viewed 6183

I'm building a component and currently I'm watching for events on input and textarea with a typed event via InputEvent: React.KeyboardEvent<HTMLInputElement> | React.KeyboardEvent<HTMLTextAreaElement>

I'm having trouble determining which event type would be fired when pasting input into these elements. Would I be reduced to using any for this or do they have an event that would be relevant when pasting input?

2 Answers

I know it has been a while since you asked, but I ran into the same problem today. Fixed it with:

event: React.ClipboardEvent

Another way to handle the paste event: You can use onPaste event in input.

paste(e){
    // e.target.value: this is prev value before paste.
  }
...
<input type="text" onPaste={this.paste} />
Related