Skip to content

Instantly share code, notes, and snippets.

@ruanvalente
Created November 26, 2024 17:34
Show Gist options
  • Save ruanvalente/e7b9af6ad1af5f51e3ed668dfa957cbc to your computer and use it in GitHub Desktop.
Save ruanvalente/e7b9af6ad1af5f51e3ed668dfa957cbc to your computer and use it in GitHub Desktop.
ConditionComponent
import React, { ReactNode } from 'react';
interface ConditionProps {
when: boolean;
children: ReactNode;
else?: ReactNode;
}
export function Condition({ when, children, else: elseContent }: ConditionProps) {
if (when) {
return <>{children}</>;
}
return elseContent ? <>{elseContent}</> : null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment