Created
May 18, 2020 22:49
-
-
Save itaditya/83b24ae9d398e6f46842d1d9e58e5f81 to your computer and use it in GitHub Desktop.
Trigger event from JS such that React can listen to them
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function setNativeValue(element, value) { | |
| const valueSetter = Object.getOwnPropertyDescriptor(element, 'value').set; | |
| const prototype = Object.getPrototypeOf(element); | |
| const prototypeValueSetter = Object.getOwnPropertyDescriptor(prototype, 'value').set; | |
| if (valueSetter && valueSetter !== prototypeValueSetter) { | |
| prototypeValueSetter.call(element, value); | |
| } else { | |
| valueSetter.call(element, value); | |
| } | |
| } | |
| elem = $('.reply-input') | |
| setNativeValue(elem, 'hello' + Math.random()) | |
| e = new Event('input', { bubbles: true }); | |
| elem.dispatchEvent(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment