Created
May 20, 2020 18:18
-
-
Save AZagatti/f8cbceb21bd834e9816551f06ea8a122 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, { PureComponent } from "react"; | |
import "./styles.css"; | |
export default class Class extends PureComponent { | |
state = { | |
name: "Zagatti", | |
count: 0 | |
}; | |
componentDidMount() { | |
document.title = `${this.state.name}'s counter`; | |
} | |
componentDidUpdate(prevProps, prevState) { | |
if (prevState.name !== this.state.name) { | |
document.title = `${this.state.name}'s counter`; | |
} | |
} | |
increment = () => { | |
this.setState(state => { | |
return { count: state.count + 1 }; | |
}); | |
}; | |
decrement = () => { | |
this.setState(state => { | |
return { count: state.count - 1 }; | |
}); | |
}; | |
updateName = e => { | |
this.setState({ name: e.target.value }); | |
}; | |
render() { | |
return ( | |
<div id="section"> | |
<div class="top"> | |
<label>Nome:</label> | |
<input | |
type="text" | |
name="name" | |
placeholder="Seu nome" | |
value={this.state.name} | |
onChange={this.updateName} | |
/> | |
</div> | |
<div class="buttons"> | |
<button onClick={this.decrement}>-</button> | |
<span>{this.state.count}</span> | |
<button onClick={this.increment}>+</button> | |
</div> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment