Skip to content

Instantly share code, notes, and snippets.

@tylerlwsmith
Created July 14, 2023 04:01
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 tylerlwsmith/666e9f5ffa08c8c7895781e24555dc7f to your computer and use it in GitHub Desktop.
Save tylerlwsmith/666e9f5ffa08c8c7895781e24555dc7f to your computer and use it in GitHub Desktop.
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