Skip to content

Instantly share code, notes, and snippets.

@marensas
Created April 2, 2018 14:32
Show Gist options
  • Save marensas/6dfd2e9c7114744d02c0bdcbc5912cc6 to your computer and use it in GitHub Desktop.
Save marensas/6dfd2e9c7114744d02c0bdcbc5912cc6 to your computer and use it in GitHub Desktop.
Typescript + React
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