Skip to content

Instantly share code, notes, and snippets.

@b3b00
Created June 19, 2019 19:36
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 b3b00/0012a39c4e0d40a0805cc486b06a79b7 to your computer and use it in GitHub Desktop.
Save b3b00/0012a39c4e0d40a0805cc486b06a79b7 to your computer and use it in GitHub Desktop.
React at CodePen
<div id="app"></app>
class Button extends React.Component {
constructor() {
super();
this.state = {
count: 0,
};
}
updateCount() {
this.setState((prevState, props) => {
return { count: prevState.count + 1 }
});
}
render() {
return (<button
onClick={() => this.updateCount()}
>
Clicked {this.state.count} times
</button>);
}
}
React.render(<Button />, document.getElementById('app'));
<script src="//cdnjs.cloudflare.com/ajax/libs/react/0.13.0/react.min.js"></script>
html, body
height: 100%
body
background: #333
display: flex
justify-content: center
align-items: center
font-family: Helvetica Neue
h1
font-size: 2em
color: #eee
display: inline-block
a
color: white
p
margin-top: 1em
text-align: center
color: #aaa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment