notes/.vscode/extensions/eckertalex.borealis-1.0.2/demo/react.tsx
2021-11-05 11:26:45 -07:00

30 lines
582 B
TypeScript

// src/components/Hello.tsx
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("!");
}