Skip to content

Instantly share code, notes, and snippets.

@HackerDaGreat57
Created August 17, 2022 00:24
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 HackerDaGreat57/f1e926b263b4009167a484233c9a85bb to your computer and use it in GitHub Desktop.
Save HackerDaGreat57/f1e926b263b4009167a484233c9a85bb to your computer and use it in GitHub Desktop.
GRxwYPj
<!-- 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>
'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