Skip to content

Instantly share code, notes, and snippets.

@KoenBrouwer
Last active December 28, 2020 00:19
Show Gist options
  • Save KoenBrouwer/2f739c4a67bfcc7e1424a50a262c101f to your computer and use it in GitHub Desktop.
Save KoenBrouwer/2f739c4a67bfcc7e1424a50a262c101f to your computer and use it in GitHub Desktop.

Revisions

  1. KoenBrouwer revised this gist Dec 28, 2020. No changes.
  2. KoenBrouwer created this gist Dec 28, 2020.
    12 changes: 12 additions & 0 deletions ConditionalWrap.tsx
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    import React from "react";

    interface ConditionalWrapProps {
    condition: boolean;
    wrap: (children: JSX.Element) => JSX.Element;
    children: JSX.Element;
    }

    const ConditionalWrap: React.FC<ConditionalWrapProps> = ({condition, children, wrap}): JSX.Element =>
    condition ? React.cloneElement(wrap(children)) : children;

    export default ConditionalWrap;