Last active
December 28, 2020 00:19
-
-
Save KoenBrouwer/2f739c4a67bfcc7e1424a50a262c101f to your computer and use it in GitHub Desktop.
Simple React component to condionally wrap something in JSX.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment