Created
May 28, 2022 11:39
-
-
Save uyriq/c3766ede23230d119398dd73531e851c to your computer and use it in GitHub Desktop.
React-adv-9 Hooks, usestate
This file contains 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
<html> | |
<head> | |
<meta charset="UTF-8" /> | |
<script src="https://unpkg.com/react@16/umd/react.development.js"></script> | |
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script> | |
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script> | |
<link rel="stylesheet" href="./style.css"> | |
</head> | |
<body> | |
<div id="root"></div> | |
<script type="text/jsx" src="script.jsx"></script> | |
</body> | |
</html> |
This file contains 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
function Boxing() { | |
/* ... = React.useState(); */ | |
const [isKnockout, setIsKnockout] = React.useState(false); | |
function handleClick() { | |
setIsKnockout(true); | |
} | |
function restoreSmile() { | |
setIsKnockout(false); | |
} | |
return ( | |
<div> | |
{!isKnockout ? ( | |
<> | |
<span>🤨</span> | |
<button onClick={handleClick}>Hook!</button> | |
</> | |
) : ( | |
<span>🥴</span> | |
)} | |
{isKnockout ? ( | |
<> | |
<span></span> | |
<button onClick={restoreSmile}> help!</button> | |
</> | |
) : ( | |
<span></span> | |
)} | |
<span>🥊</span> | |
</div> | |
); | |
} | |
ReactDOM.render(( | |
<Boxing /> | |
), document.querySelector('#root')); |
This file contains 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
*, | |
*::before, | |
*::after { | |
box-sizing: border-box; | |
} | |
body { | |
background: #202020; | |
font-family: Helvetica, Arial, sans-serif; | |
} | |
#root { | |
height: 100vh; | |
} | |
#root > div { | |
padding: 20px; | |
} | |
span { | |
font-size: 160px; | |
vertical-align: middle; | |
margin: 0 -15px; | |
} | |
button { | |
margin: 0 40px; | |
width: 150px; | |
height: 50px; | |
color: #fff; | |
background-color: #FF7A00; | |
border: none; | |
border-radius: 20px; | |
cursor: pointer; | |
font-weight: bold; | |
font-size: 36px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment