honghaitzz11 6 years ago
parent
commit
616c544598
1 changed files with 46 additions and 0 deletions
  1. 46 0
      src/components/Hello.tsx

+ 46 - 0
src/components/Hello.tsx

@@ -0,0 +1,46 @@
+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>
+    );
+}
+
+
+
+function getExclamationMarks(numChars: number) {
+    return Array(numChars + 1).join('!');
+}
+
+
+class Hello extends React.Component<Props, object> {
+    render() {
+      const { name, enthusiasmLevel = 1 } = this.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;