Skip to content

Instantly share code, notes, and snippets.

@nasliedkov
Forked from OlivierSte/conditionalWrapper.jsx
Created February 8, 2020 11:03
Show Gist options
  • Select an option

  • Save nasliedkov/03ba52ed5753a44e555a66138a836cc7 to your computer and use it in GitHub Desktop.

Select an option

Save nasliedkov/03ba52ed5753a44e555a66138a836cc7 to your computer and use it in GitHub Desktop.
const ConditionalWrapper = ({ condition, wrapper, children }) =>
condition ? wrapper(children) : children;
@nasliedkov
Copy link
Author

Usage:

const isPreview = true

 <ConditionalWrapper 
        condition={isPreview}
        wrapper={children => 
            <MessagesButton onClick={handleClick}>
              {children}
            </MessagesButton>
        }>
</ConditionalWrapper>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment