Last active
January 31, 2025 23:03
-
-
Save tammyhart/c118c733501e1fad991015c230f54ab5 to your computer and use it in GitHub Desktop.
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
type ConditionalWrap<T> = { | |
children: React.ReactNode | |
condition: boolean | |
Wrap: T | |
wrapProps?: T extends React.ComponentType<infer P> ? P : object | |
} | |
const ConditionalWrap = <T extends React.ElementType>({ | |
children, | |
condition, | |
Wrap, | |
wrapProps, | |
}: ConditionalWrap<T>) => | |
// eslint-disable-next-line @typescript-eslint/no-explicit-any | |
condition ? <Wrap {...(wrapProps as any)}>{children}</Wrap> : children | |
export default ConditionalWrap |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment