Skip to content

Instantly share code, notes, and snippets.

@treyhuffine
Last active July 3, 2018 15:22
Show Gist options
  • Save treyhuffine/b1311a7f569c5897631dc7557cf0aa2e to your computer and use it in GitHub Desktop.
Save treyhuffine/b1311a7f569c5897631dc7557cf0aa2e to your computer and use it in GitHub Desktop.
A TypeScript class component
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