Created
June 10, 2020 01:35
-
-
Save sandrabosk/5f08a1f71e7045c5b01003b5425d0274 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 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