Skip to content

Instantly share code, notes, and snippets.

@sandrabosk
Created June 10, 2020 01:35
Show Gist options
  • Save sandrabosk/5f08a1f71e7045c5b01003b5425d0274 to your computer and use it in GitHub Desktop.
Save sandrabosk/5f08a1f71e7045c5b01003b5425d0274 to your computer and use it in GitHub Desktop.
import React from 'react';
class ExampleComponent extends React.Component {
state = {
didClick: true
};
handleClick = () => {
if (this.state.didClick) {
this.setState({ didClick: false });
} else {
this.setState({ didClick: true });
}
};
render() {
return (
<div>
{/* we will cover conditionals soon, so don't worry if you don't understand the following line */}
{this.state.didClick ? <h2>Did I click?</h2> : <h2>Yes you did!</h2>}
<button onClick={this.handleClick}>Click here!</button>
</div>
);
}
}
export default ExampleComponent;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment