Last active
September 14, 2016 15:59
-
-
Save eldh/38711960f1465486de9e36f0e7a5c820 to your computer and use it in GitHub Desktop.
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
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