Created
July 14, 2023 04:01
-
-
Save tylerlwsmith/666e9f5ffa08c8c7895781e24555dc7f 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 SharedProps = { | |
multiple: boolean; | |
name: string; | |
} | |
type Multiple = SharedProps & { | |
multiple: true; | |
callback: (items: string[]) => void; | |
} | |
type Single = SharedProps & { | |
multiple: false; | |
callback: (item: string) => void; | |
} | |
function UploadComponent({multiple, callback}: Single | Multiple) { | |
function handleClick() { | |
if (multiple){ | |
callback(["1", "2", "3"]) | |
} else { | |
callback("1") | |
} | |
} | |
return ( | |
<button onClick={handleClick}>Run callback</button> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment