Skip to content

Instantly share code, notes, and snippets.

@isacjunior
Last active March 27, 2019 02:53
Show Gist options
  • Save isacjunior/be49c50d735ed32c6359f6e75dacf188 to your computer and use it in GitHub Desktop.
Save isacjunior/be49c50d735ed32c6359f6e75dacf188 to your computer and use it in GitHub Desktop.
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