Last active
March 27, 2019 02:53
-
-
Save isacjunior/be49c50d735ed32c6359f6e75dacf188 to your computer and use it in GitHub Desktop.
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 React, { Component } from 'react' | |
interface Props { | |
initialCount: number | |
} | |
interface State { | |
count: number | |
} | |
class CounterClass extends Component<Props, State> { | |
constructor(props: Props) { | |
super(props) | |
const { initialCount } = props | |
this.state = { | |
count: initialCount | |
} | |
this.increment = this.increment.bind(this) | |
} | |
increment() { | |
this.setState({ count: this.state.count + 1 }) | |
} | |
render() { | |
const { count } = this.state | |
return ( | |
<button onClick={this.increment}>{count}</button> | |
) | |
} | |
} | |
export default CounterClass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment