Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React TypeScript Input Paste Event

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?

like image 484
Jared Avatar asked Oct 25 '18 23:10

Jared


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
like image 54
LMox Avatar answered Nov 19 '22 08:11

LMox


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} />
like image 36
Diamond Avatar answered Nov 19 '22 07:11

Diamond