Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@shurane
Last active July 26, 2017 01:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shurane/ffcba49be3e4570488ea3dda3db2e759 to your computer and use it in GitHub Desktop.
Save shurane/ffcba49be3e4570488ea3dda3db2e759 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
import { debounce } from 'lodash';
class SearchBox extends Component {
constructor(props) {
super(props);
this.state = {value: ''};
// https://stackoverflow.com/a/28046731/198348
// this.handleChange = this.handleChange.bind(this);
this.handleChange = debounce(this.handleChange.bind(this), 300);
}
handleChange(event) {
event.persist();
console.log(event);
this.setState({value: event.target.value});
console.log(event.target.value);
}
render() {
return (
<label>
Search: <input type="text" value={this.state.value} onChange={this.handleChange} />
</label>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment