Skip to content

Instantly share code, notes, and snippets.

@diego-miranda-ng
Created August 22, 2020 02:22
Show Gist options
  • Save diego-miranda-ng/ad9bdb369154aaef34f582069159be60 to your computer and use it in GitHub Desktop.
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.
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