Last active
November 3, 2019 01:14
-
-
Save Falconiere/5ffc2948d82886b2df495b3f1805e07e to your computer and use it in GitHub Desktop.
A simple component before hooks
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, { PureComponent, Fragment } from 'react' | |
export default class SimpleComponent extends PureComponent { | |
constructor(props){ | |
super(props) | |
this.state = { counter: 0 } | |
} | |
handleOnClick = e => { | |
e.preventDefault() | |
const { counter } = this.state | |
this.setState({ counter: counter + 1 }) | |
} | |
render = () => { | |
const { counter } = this.state | |
return ( | |
<Fragment> | |
<h1>Counter: {counter} </h1> | |
<button onClick={e => this.handleOnClick(e)}> Click me </button> | |
</Fragment> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment