A Pen by Akshat Singh on CodePen.
Created
August 17, 2022 00:24
-
-
Save twisted-nematic57/f1e926b263b4009167a484233c9a85bb to your computer and use it in GitHub Desktop.
GRxwYPj
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
<!-- index.html: The starting page for the something project (just activates React and goes from there) --> | |
<!DOCTYPE html> | |
<html> | |
<head> <!-- Stuff that's not visible on the web page itself, i.e. favicons and title --> | |
<link rel="stylesheet" href="index.css"> <!-- Load the CSS for this page --> | |
<script src="index.js"></script> <!-- Load the JavaScript for this page --> | |
<link rel="icon" href="assets/suitcase_general.png"> | |
<title>something</title> | |
<!-- Load React --> | |
<script src="https://unpkg.com/react@18/umd/react.development.js" crossorigin></script> | |
<script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js" crossorigin></script> | |
<!-- Load the React components --> | |
<script src="like_button.js"></script> | |
</head> | |
<body> <!-- Stuff that you see on the website itself --> | |
<!-- React stuff goes in this div. Let's go! --> | |
<div id="main_container"></div> | |
</body> | |
</html> |
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
'use strict'; | |
const e = React.createElement; | |
document.body.style = 'background: red;'; | |
class LikeButton extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { liked: false }; | |
} | |
render() { | |
if (this.state.liked) { | |
return 'You liked this.'; | |
} | |
return e( | |
'button', | |
{ onClick: () => this.setState({ liked: true }) }, | |
'Like' | |
); | |
} | |
} | |
const domContainer = document.querySelector('#main_container'); | |
const root = ReactDOM.createRoot(domContainer); | |
root.render(e(LikeButton)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment