Skip to content

Instantly share code, notes, and snippets.

@sibiraj-s
Created April 9, 2019 18:59
Show Gist options
  • Save sibiraj-s/caadb2c8d4ed23175db1d2707217f4f3 to your computer and use it in GitHub Desktop.
Save sibiraj-s/caadb2c8d4ed23175db1d2707217f4f3 to your computer and use it in GitHub Desktop.
React - Manually trigger onChange Event
// Use HTMLInputElement for text input
const nativeTextAreaValueSetter = Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, 'value').set
nativeTextAreaValueSetter.call(inputRef, newTextareaValue)
const inputEvent = new Event('input', { bubbles: true })
inputRef.dispatchEvent(inputEvent)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment