Johnhong9527 5 lat temu
rodzic
commit
3fcec9a930
1 zmienionych plików z 27 dodań i 0 usunięć
  1. 27 0
      src/components/Hello.tsx

+ 27 - 0
src/components/Hello.tsx

@@ -0,0 +1,27 @@
+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('!');
+}