I created UI where pasting text into textarea sends request to my API immediately. The problem is that paste event doesn't seem to be aware of the pasted value, unless I'm missing something. If I use event.target.value directly, it returns the value from before the pasting occured.
I used setTimeout() with 0ms and it works (but I'm not happy):
document.getElementById('my-textarea').addEventListener('paste', event => {
setTimeout(() => {
const contents = event.target.value;
// fetch() using `contents`
}, 0);
});
Is there some cleaner way?