Created
August 22, 2020 02:22
-
-
Save diego-miranda-ng/ad9bdb369154aaef34f582069159be60 to your computer and use it in GitHub Desktop.
Exemplo da utilização do ciclo de vida em componentes de classe.
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 from "react"; | |
export default class App extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
count: 0, | |
person: "TheAlfadur" | |
}; | |
} | |
componentDidMount() { | |
console.log(this.state.count); | |
console.log(this.state.person); | |
} | |
componentDidUpdate() { | |
console.log(this.state.count); | |
console.log(this.state.person); | |
} | |
render() { | |
return ( | |
<> | |
<button onClick={() => this.setState({ count: this.state.count + 1 })}> | |
INCREMENTAR O CONTADOR | |
</button> | |
<button | |
onClick={() => | |
this.setState({ | |
person: | |
this.state.person === "TheAlfadur" ? "Diego" : "TheAlfadur" | |
}) | |
} | |
> | |
ALTERAR PESSOA | |
</button> | |
</> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment