Created
November 26, 2024 17:34
-
-
Save ruanvalente/e7b9af6ad1af5f51e3ed668dfa957cbc to your computer and use it in GitHub Desktop.
ConditionComponent
This file contains hidden or 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, { 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