reactjs – Type text into a React input using javascript (Tampermonkey script)?

React doesn’t expose component instances, so they aren’t reachable without tampering an application on initialization, if this is possible.

Input values should be changed like they would be with vanilla JavaScript, by emitting DOM events.

React provides utility library that has helper functions to do that.

Here’s an example. An input:

 this.setState({ name: e.target.value })} />

And user script that runs after React application initialization:

import { Simulate } from 'react-dom/test-utils';

const input = document.getElementById('input');
input.value="Foo";
Simulate.change(input);

Read more here: Source link