Skip to content

Instantly share code, notes, and snippets.

@rafaelrinaldi
Created April 12, 2017 23:54
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 rafaelrinaldi/3d44c35c68c477fc9cb69942ecfa04fe to your computer and use it in GitHub Desktop.
Save rafaelrinaldi/3d44c35c68c477fc9cb69942ecfa04fe to your computer and use it in GitHub Desktop.
Simple functional stateless component to make component rendering declarative and avoid JSX evaluation magic.
import { Children, PropTypes } from 'react';
const Visibility = ({ visible, children }) => (
visible ? Children.only(children) : null
);
Visibility.defaultProps = {
visible: true,
};
Visibility.propTypes = {
visible: PropTypes.bool,
children: PropTypes.element.isRequired,
};
export default Visibility;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment