Skip to content

Instantly share code, notes, and snippets.

@BrodaNoel
Created February 11, 2018 22:33
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 BrodaNoel/766fb72f4a5cc6935cf931864e0e7870 to your computer and use it in GitHub Desktop.
Save BrodaNoel/766fb72f4a5cc6935cf931864e0e7870 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