Skip to content

Instantly share code, notes, and snippets.

@NoamELB
Created November 18, 2017 18:34
Show Gist options
  • Save NoamELB/65ceb464a8d37f48b1177cbfcf63eb0b to your computer and use it in GitHub Desktop.
Save NoamELB/65ceb464a8d37f48b1177cbfcf63eb0b to your computer and use it in GitHub Desktop.
leashed component
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}/>
);
}
}
@marcinlichwala
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment