Skip to content

Instantly share code, notes, and snippets.

@taeber
Created October 20, 2017 16:33
Show Gist options
  • Save taeber/e3ad89dc5124d90d9f6916f4788084b7 to your computer and use it in GitHub Desktop.
Save taeber/e3ad89dc5124d90d9f6916f4788084b7 to your computer and use it in GitHub Desktop.
React Visible Component
// 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