Skip to content

Instantly share code, notes, and snippets.

@reciosonny
Created December 22, 2019 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reciosonny/276a618fc31ee974cd6248b83d99898f to your computer and use it in GitHub Desktop.
Save reciosonny/276a618fc31ee974cd6248b83d99898f to your computer and use it in GitHub Desktop.
class App extends React.Component {
state = { clicked: false, initialized: false };
componentDidMount() {
this.setState({ initialized: true });
}
setClicked = () => {
this.setState({ clicked: true });
}
render() {
const { initialized, clicked } = this.state;
return (
<div className="App">
{initialized && <h1>Initialized</h1>}
<h1 onClick={() => this.setClicked(true)}>Please click me!</h1>
{clicked && <h2>You clicked an object!</h2>}
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment