Created
October 28, 2018 23:41
-
-
Save haldarmahesh/f80af7eb483bfb996012b8f8abf10f40 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' | |
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