Created
October 20, 2017 16:33
-
-
Save taeber/e3ad89dc5124d90d9f6916f4788084b7 to your computer and use it in GitHub Desktop.
React Visible Component
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
// before: | |
var LoginLink = props => ( | |
{!props.loggedIn && | |
<a href="#login">Login</a> | |
} | |
); | |
const Visible = props => props.when && props.children; | |
// after: | |
var LoginLink = props => ( | |
<Visible when={!props.loggedIn}> | |
<a href="#login">Login</a> | |
</Visible> | |
); | |
// The "before" version is terser but "after" looks better when there are many such components |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment