Skip to content

Instantly share code, notes, and snippets.

@MicheleBertoli
Created January 8, 2016 21:11
Show Gist options
  • Save MicheleBertoli/7fbd5558e1a32a673c2d to your computer and use it in GitHub Desktop.
Save MicheleBertoli/7fbd5558e1a32a673c2d to your computer and use it in GitHub Desktop.
RenderIf
const RenderIf = (Component, condition) => {
class Child extends Component {
constructor(props) {
super(props);
}
render() {
if (condition(this.props, this.state)) {
return super.render();
}
return null;
}
}
return Child;
}
const Yo = React.createClass({
render() {
return <div>Yo</div>;
}
});
const EnhancedYo = RenderIf(Yo, (props, state) => props.shouldRender);
ReactDOM.render(<EnhancedYo shouldRender={true} />, document.body);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment