Skip to content

Instantly share code, notes, and snippets.

@BrodaNoel
Created February 11, 2018 22:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BrodaNoel/fab551ee47d3bc35a75b59f3beced30c to your computer and use it in GitHub Desktop.
Save BrodaNoel/fab551ee47d3bc35a75b59f3beced30c to your computer and use it in GitHub Desktop.
// src/components/Conditional.jsx
const Conditional = (props) => {
return(
!!props.if && props.children
);
}
export default Conditional;
// Implementation:
import Conditional from 'components/Conditional';
render() {
return (
<div className="App">
<h1>The title</h1>
<Conditional if={this.state.movies.length > 0}>
<h1>Movie list</h1>
<MovieList data={this.state.movies} />
</Conditional>
<Conditional if={this.state.comics.length > 0}>
<h1>Comic list</h1>
<ComicList data={this.state.comics} />
</Conditional>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment