Last active
January 31, 2019 21:20
-
-
Save frasergr/13d927165176e9adc7c802ac58e54ec6 to your computer and use it in GitHub Desktop.
React _.debounce input taken from: https://github.com/facebook/react/issues/1360#issuecomment-333969294
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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