Last active
December 13, 2023 03:20
-
-
Save sethdavis512/874d8ab8d5cd077b851951817be7c883 to your computer and use it in GitHub Desktop.
A component that wraps children with a tag based on the condition
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 type { ReactNode } from 'react'; | |
interface ConditionalWrapperProps { | |
condition: boolean; | |
wrapper: (children: ReactNode) => ReactNode; | |
children: ReactNode; | |
} | |
export default function ConditionalWrapper({ | |
condition, | |
wrapper, | |
children | |
}: ConditionalWrapperProps) { | |
return condition ? wrapper(children) : children; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment