Skip to content

Instantly share code, notes, and snippets.

@khadorkin
Forked from kitze/conditionalwrap.js
Created September 28, 2019 20:13
Show Gist options
  • Save khadorkin/6ab52d9c0d09687692f49d729f8b88cb to your computer and use it in GitHub Desktop.
Save khadorkin/6ab52d9c0d09687692f49d729f8b88cb 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