Skip to content

Instantly share code, notes, and snippets.

@haldarmahesh
Created October 28, 2018 23:41
Show Gist options
  • Save haldarmahesh/f80af7eb483bfb996012b8f8abf10f40 to your computer and use it in GitHub Desktop.
Save haldarmahesh/f80af7eb483bfb996012b8f8abf10f40 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react'
export default class Counter extends Component {
constructor(props) {
super(props);
this.state = {
counter: 0
}
this.handleIncrement = this.handleCounter.bind(this);
}
componentDidMount() {
document.title = "Count is " + this.state.counter;
}
componentDidUpdate() {
document.title = "Count is " + this.state.counter;
}
handleCounter(value) {
this.setState({
counter: value
});
}
render() {
return (
<div>
<div>
<button onClick={() => this.handleCounter(this.state.counter + 1)}> + Increment</button>
<button onClick={() => this.handleCounter(this.state.counter - 1)}> - Decrement</button>
</div>
<div>
Current: {this.state.counter}
</div>
</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment