Last active
November 20, 2018 01:09
-
-
Save ryee-dev/433bf2bf99a648252796fa8d2c204975 to your computer and use it in GitHub Desktop.
[React TypeScript Notes] Using typescript with react #react #typescript
This file contains 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
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