Last active
July 3, 2018 15:22
-
-
Save treyhuffine/b1311a7f569c5897631dc7557cf0aa2e to your computer and use it in GitHub Desktop.
A TypeScript class component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import * as React from 'react'; | |
| interface IProps { | |
| countBy?: number; | |
| } | |
| interface IState { | |
| count: number; | |
| } | |
| class Description extends React.Component<IProps, IState> { | |
| public static defaultProps: Partial<IProps> = { | |
| countBy: 1, | |
| }; | |
| public state: IState = { | |
| count: 0, | |
| }; | |
| public increase = () => { | |
| const countBy: number = this.props.countBy!; | |
| const count = this.state.count + countBy; | |
| this.setState({ count }); | |
| }; | |
| public render() { | |
| return ( | |
| <div> | |
| <p>My favorite number is {this.state.count}</p> | |
| <button onClick={this.increase}>Increase</button> | |
| </div> | |
| ); | |
| } | |
| } | |
| export default Description; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment