Skip to content

Instantly share code, notes, and snippets.

@ryee-dev
Last active November 20, 2018 01:09
Show Gist options
  • Save ryee-dev/433bf2bf99a648252796fa8d2c204975 to your computer and use it in GitHub Desktop.
Save ryee-dev/433bf2bf99a648252796fa8d2c204975 to your computer and use it in GitHub Desktop.
[React TypeScript Notes] Using typescript with react #react #typescript
interface CounterState {
count: number;
}
class App extends Component<{}, CounterState> {
constructor(props: any) {
super(props);
this.state = {
count: 0
};
this.handleIncrement = this.handleIncrement.bind(this);
this.handleDecrement = this.handleDecrement.bind(this);
}
handleIncrement = () => {
const { count } = this.state;
this.setState({
count: count + 1
});
};
handleDecrement = () => {
const { count } = this.state;
this.setState({
count: count - 1
});
};
render() {
const { count } = this.state;
return (
<div className="App">
<header className="App-header">
<p>{count}</p>
<div onClick={this.handleIncrement}>+</div>
<div onClick={this.handleDecrement}>-</div>
</header>
</div>
);
}
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment