Created
January 8, 2016 21:11
-
-
Save MicheleBertoli/7fbd5558e1a32a673c2d to your computer and use it in GitHub Desktop.
RenderIf
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
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