Created
June 28, 2018 16:11
-
-
Save SaraVieira/eaa1981176dfec09abcbf7fc1c245915 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>Document</title> | |
</head> | |
<body> | |
<style> | |
html, | |
body, | |
#app { | |
margin: 0; | |
padding: 0; | |
background: #001f3f; | |
height: 100%; | |
color: white; | |
} | |
button { | |
height: 40px; | |
padding: 8px 10px; | |
border: none; | |
width: 200px; | |
margin: 10px 0; | |
font-size: 18px; | |
color: #111111; | |
} | |
.wrapper { | |
width: 100%; | |
height: 100%; | |
display: flex; | |
flex-direction: column; | |
font-family: Avenir, Arial, Helvetica, sans-serif; | |
font-size: 60px; | |
align-items: center; | |
justify-content: center; | |
} | |
.label { | |
font-size: 14px; | |
} | |
</style> | |
<div id="app"></div> | |
<!-- Note: when deploying, replace "development.js" with "production.min.js". --> | |
<script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script> | |
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script> | |
<script> | |
class Wrapper extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { counter: 0 }; | |
this.updateCounter = this.updateCounter.bind(this) | |
} | |
updateCounter(value) { | |
this.setState(({ counter }) => ({ | |
counter: counter + 1 | |
})) | |
} | |
render() { | |
return React.createElement( | |
'div', | |
{ className: 'wrapper' }, | |
'Click the Button', | |
Input({ updateCounter: this.updateCounter }), | |
Label({ counter: this.state.counter }) | |
); | |
} | |
} | |
function Input({ updateCounter }) { | |
return React.createElement( | |
'button', | |
{ | |
onClick: (e) => updateCounter(e.target.value), | |
}, | |
'Click Me' | |
); | |
} | |
function Label({ counter }) { | |
return React.createElement( | |
'label', | |
{ className: 'label' }, | |
"You have clicked " + counter + " times" | |
); | |
} | |
var container = document.querySelector('#app'); | |
ReactDOM.render( | |
React.createElement(Wrapper), | |
container | |
); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment