Created
November 18, 2017 18:34
-
-
Save NoamELB/65ceb464a8d37f48b1177cbfcf63eb0b to your computer and use it in GitHub Desktop.
leashed component
This file contains hidden or 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
export default class LeashedOne extends React.Component { | |
constructor(props) { | |
super(props); | |
this.onChange = this.onChange.bind(this); | |
this.onChangeDebounce = _.debounce(value => this.props.onChange(value), 300); | |
} | |
onChange(e) { | |
this.onChangeDebounce(e.target.value); | |
} | |
render () { | |
return ( | |
<input onChange={this.onChange}/> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello @NoamELB! Thanks for the great article about React performance. 👍
It looks like there is a typo in the code above I believe. You should use the props passed to the constructor while creating the debounced handler in it.
It should read:
this.onChangeDebounce = _.debounce(value => props.onChange(value), 300);
Cheers!