Skip to content

Instantly share code, notes, and snippets.

@rachelnabors
Created August 18, 2021 20:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rachelnabors/c64b3aeace8a191cf5ea6fb5202e66c9 to your computer and use it in GitHub Desktop.
Save rachelnabors/c64b3aeace8a191cf5ea6fb5202e66c9 to your computer and use it in GitHub Desktop.
Add React in One Minute
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Add React in One Minute</title>
</head>
<body>
<h2>Add React in One Minute</h2>
<p>This page demonstrates using React with no build tooling.</p>
<p>React is loaded as a script tag.</p>
<!-- We will put our React component inside this div. -->
<div id="component-goes-here"></div>
<!-- Load React. -->
<!-- Note: when deploying, replace "development.js" with "production.min.js". -->
<script src="https://unpkg.com/react@17/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@17/umd/react-dom.development.js" crossorigin></script>
<!-- Load your React component. -->
<script src="like_button.js"></script>
</body>
</html>
'use strict';
function LikeButton() {
const [liked, setLiked] = React.useState(false);
if (liked) {
return 'You liked this!';
}
return React.createElement(
'button',
{
onClick: () => setLiked(true),
},
'Like'
);
}
const domContainer = document.getElementById('component-goes-here');
ReactDOM.render(React.createElement(LikeButton), domContainer);
@rachelnabors
Copy link
Author

Adding JSX?

This example shows React without JSX. To add JSX, check out the official docs: http://reactjs.org/docs/add-react-to-a-website#try-react-with-jsx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment