Files
behavior3editor/src/components/Hello.tsx
T
2020-10-09 16:11:20 +08:00

28 lines
649 B
TypeScript

import * as React from 'react';
export interface Props {
name: string;
enthusiasmLevel?: number;
}
export default 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>
);
}
}
function getExclamationMarks(numChars: number) {
return Array(numChars + 1).join('!');
}