Skip to content

Instantly share code, notes, and snippets.

@zeckdude
Forked from kitze/conditionalwrap.js
Created August 7, 2018 20:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeckdude/46120f817d79ccacf9e01b2d95543629 to your computer and use it in GitHub Desktop.
Save zeckdude/46120f817d79ccacf9e01b2d95543629 to your computer and use it in GitHub Desktop.
one-line React component for conditionally wrapping children
import React from 'react';
const ConditionalWrap = ({condition, wrap, children}) => condition ? wrap(children) : children;
const Header = ({shouldLinkToHome}) => (
<div>
<ConditionalWrap
condition={shouldLinkToHome}
wrap={children => <a href="/">{children}</a>}
>
<img src="logo.png"/>
</ConditionalWrap>
</div>
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment