Skip to content

Instantly share code, notes, and snippets.

@eldh
Last active September 14, 2016 15:59
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 eldh/38711960f1465486de9e36f0e7a5c820 to your computer and use it in GitHub Desktop.
Save eldh/38711960f1465486de9e36f0e7a5c820 to your computer and use it in GitHub Desktop.
class DelayRender extends React.Component {
constructor({onPropsChange, ...props}) {
super(...arguments)
this.state = {props}
}
componentWillReceiveProps(props) {
this.setState({isWaiting: true})
this.props.onPropsChange(() => {this.setState({props, isWaiting: false})})
},
shouldComponentUpdate(newProps, newState) { return this.state !== newState; },
render() {
return React.cloneElement(
React.Children.only(this.props.children),
{...this.state.props, isWaiting: this.state.isWaiting}
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment