Reactのイベントをトリガーする
dispatchEventとかで検索してもなかなか見つからなかったのでメモ。
ここに書いてある: https://stackoverflow.com/questions/23892547/what-is-the-best-way-to-trigger-onchange-event-in-react-js
code: js
const inputTextAreaWithOverReact16(elem, value) => {
const nativeInputValueSetter = Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, "value").set;
nativeInputValueSetter.call(elem, value);
const e = new Event('input', { bubbles: true });
elem.dispatchEvent(e);
};
const inputWithOverReact16(elem, value) => {
const nativeInputValueSetter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value").set;
nativeInputValueSetter.call(elem, value);
const e = new Event('input', { bubbles: true });
elem.dispatchEvent(e);
};
const inputWithUnderReact16(elem, value) => {
const e = new Event('input', { bubbles: true });
e.simulated = true;
elem.value = value;
elem.dispatchEvent(e);
};
#React