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.

Revisions

  1. ruanvalente created this gist Nov 26, 2024.
    14 changes: 14 additions & 0 deletions Condition.tsx
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    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;
    }