Last active
February 16, 2020 16:40
-
-
Save Joooohee/47773465219a8a6177b1e0cc42501752 to your computer and use it in GitHub Desktop.
react-basics
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> | |
<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@6/babel.min.js"></script> | |
</head> | |
<body> | |
<div id="root"></div> | |
<!-- 결과 : <div id="root"><button>Like></button></div> --> | |
<script type="text/babel"> | |
class LikeButton extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
liked: false | |
}; | |
} | |
render() { | |
return ( | |
<button | |
type="submit" | |
onClick={() => { | |
this.setState({ liked: true }); | |
}} | |
> | |
{this.state.liked === true ? "Liked" : "Like"} | |
</button> | |
// JSX (JS + XML) | |
); | |
} | |
} | |
</script> | |
<script type="text/babel"> | |
ReactDOM.render(<LikeButton />, document.querySelector("#root")); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment