Skip to content

Instantly share code, notes, and snippets.

@frasergr
Last active January 31, 2019 21:20
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 frasergr/13d927165176e9adc7c802ac58e54ec6 to your computer and use it in GitHub Desktop.
Save frasergr/13d927165176e9adc7c802ac58e54ec6 to your computer and use it in GitHub Desktop.
class Input extends React.Component
{
constructor(props) {
super(props);
this.state = {
inputText: '',
currentUrl: ''
};
this.handleChange = this.handleChange.bind(this);
this.updateUrl = this.updateUrl.bind(this);
// Debounce
this.updateUrl = _.debounce(this.updateUrl, 500);
}
handleChange(e) {
this.setState({
inputText: e.target.value
});
// It's debounced!
this.updateUrl();
}
updateUrl() {
this.setState({
currentUrl: this.state.inputText
});
}
render() {
return (
<div>
<input value={this.state.inputText} />
<MyVideo url={this.state.currentUrl} />
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment