Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Counter extends React.Component {
- constructor() {
- super();
- this.state = {
- count: 0,
- }
- this.handleClick = this.handleClick.bind(this);
- }
- handleClick = () => {
- const newCount = this.state.count + 1;
- this.setState({count: newCount});
- }
- render() {
- const { count } = this.state;
- return (
- <div>
- <p> You've clicked the button {count} times. </p>
- <button onClick={this.handleClick}>Click Me </button>
- </div>
- )
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement