I'm trying to debounce textarea value with react/redux and show the debounced value in div#preview
but i'm getting synthetic event warning after first function call.
I have reducer for handling textarea value state which is working as intended, but for simplicity i've wrote local state in this snippet.
If there is a better method besides debounce
to avoid react rerendering after each keypress
I would love to know. Thanks in advance.
class TextArea extends React.Component {
constructor(props){
super(props);
this.state = {foo: ''}
}
handleInputChange = _.debounce((e) => {
e.persist();
let value = e.target.value;
this.setState({foo: value});
}, 300);
render() {
return (
<div>
<textarea onChange={(e)=>this.handleInputChange(e)} value={this.state.foo}></textarea>
<p id="preview">{this.state.foo}</p>
</div>
);
}
}
ReactDOM.render(
<TextArea />,
document.getElementById("react")
);
<div id="react"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>