Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React: How to read external onChange events

How to read the external text change events in react.

The extensions like Grammarly and Auto Text Expander update the text inside textarea, but no react onChange or onInput event is fired after the change. As the result, state is not updated and the condition is inconsistent (different values in textarea and component's state). One way is to read the dom value on submit, but that's not the perfect solution for my scenario, as some other actions depends on the current value of the textarea. Any good solution?

PS: I'm asking for a generic solution. Changing extensions code is not an option.

like image 988
manish Avatar asked Oct 24 '16 07:10

manish


1 Answers

I checked this and it works fine for me. Spelling and grammar corrected by Grammarly updates the component state.

<textarea value={this.state.testText} onChange={(e) => {this.setState({testText: e.target.value} )}} />
like image 64
Kamlesh Tajpuri Avatar answered Oct 10 '22 00:10

Kamlesh Tajpuri