Skip to content

Instantly share code, notes, and snippets.

@gaearon
Last active January 26, 2024 11:25
Star You must be signed in to star a gist
Save gaearon/6668a1f6986742109c00a581ce704605 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="like_button_container"></div>
<!-- Load React. -->
<!-- Note: when deploying, replace "development.js" with "production.min.js". -->
<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 our React component. -->
<script src="like_button.js"></script>
</body>
</html>
'use strict';
const e = React.createElement;
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('#like_button_container');
const root = ReactDOM.createRoot(domContainer);
root.render(e(LikeButton));
@gmumdzhiev
Copy link

Is it possible to implement the same logic , but for an react-native application ?

@melashu
Copy link

melashu commented Sep 6, 2022

Great

@olamiji-8
Copy link

Wow this is nice

@AminVost
Copy link

dosen't work for me , please help
I want to use it in a pre-built project
foot
html
js

@shegy28
Copy link

shegy28 commented Jan 9, 2023

Really helpful thanks alot

@shegy28
Copy link

shegy28 commented Jan 9, 2023

Is it possible to implement the same logic , but for an react-native application ?

yes I think so

@exezick
Copy link

exezick commented Feb 9, 2023

I have a question guys, what if I created another component and I want to call it or import it inside like_button.js how to do that?

@jo777750
Copy link

jo777750 commented Feb 9, 2023 via email

@exezick
Copy link

exezick commented Feb 9, 2023

I tried to import a component using react cdn but I cand import it, I posted the problem in stack overflow. https://stackoverflow.com/questions/75375157/how-to-import-my-component-using-reactjs-cdn?noredirect=1#comment133002007_75375157

@MAB015
Copy link

MAB015 commented Feb 28, 2023

Great

@Arifurrex
Copy link

thanks

@onigetoc
Copy link

onigetoc commented Sep 7, 2023

jsfiddle demo but without the js url component but direct inside the javascript:
https://jsfiddle.net/onigetoc/ua2hoqm1/

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