Skip to content

Instantly share code, notes, and snippets.

@rachelnabors
Created Aug 18, 2021
Embed
What would you like to do?
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

rachelnabors commented Aug 18, 2021

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