Skip to content

Instantly share code, notes, and snippets.

@piecyk
Created March 3, 2016 20:26
Show Gist options
  • Select an option

  • Save piecyk/c12c6010c574e5c1d813 to your computer and use it in GitHub Desktop.

Select an option

Save piecyk/c12c6010c574e5c1d813 to your computer and use it in GitHub Desktop.
const DebounceRender = React.createClass({
mixins: [React.addons.PureRenderIgnoreFunctionsMixin],
isRender: false,
getDefaultProps() {
return {wait: 400, showLoading: true};
},
componentWillMount() {
this.forceRender = _.debounce(this.forceRender, this.props.wait);
},
forceRender() {
this.isRender = true;
this.forceUpdate(() => {this.isRender = false;});
},
render() {
this.forceRender();
return this.isRender ? this.props.children :
(this.props.showLoading ? (<LoadingIndicator/>) : null);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment