Created
April 2, 2018 14:32
-
-
Save marensas/6dfd2e9c7114744d02c0bdcbc5912cc6 to your computer and use it in GitHub Desktop.
Typescript + React
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 * as React from 'react'; | |
export interface Props { | |
name: string; | |
enthusiasmLevel?: number; | |
} | |
function Hello({ name, enthusiasmLevel = 1 }: Props) { | |
if (enthusiasmLevel <= 0) { | |
throw new Error('You could be a little more enthusiastic. :D'); | |
} | |
return ( | |
<div className="hello"> | |
<div className="greeting"> | |
Hello {name + getExclamationMarks(enthusiasmLevel)} | |
</div> | |
</div> | |
); | |
} | |
export default Hello; | |
// helpers | |
function getExclamationMarks(numChars: number) { | |
return Array(numChars + 1).join('!'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment