Created
April 12, 2017 23:54
-
-
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.
This file contains 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
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