Skip to content

Instantly share code, notes, and snippets.

@sethdavis512
Last active December 13, 2023 03:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sethdavis512/874d8ab8d5cd077b851951817be7c883 to your computer and use it in GitHub Desktop.
Save sethdavis512/874d8ab8d5cd077b851951817be7c883 to your computer and use it in GitHub Desktop.
A component that wraps children with a tag based on the condition
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