Skip to content

Instantly share code, notes, and snippets.

@floweb
Forked from RickWong/react.html
Last active June 18, 2018 11:19
Show Gist options
  • Save floweb/f9397f4dd3c15d5404318e9ef852755e to your computer and use it in GitHub Desktop.
Save floweb/f9397f4dd3c15d5404318e9ef852755e to your computer and use it in GitHub Desktop.
Write React apps in 1 HTML file
<html>
<meta charset="utf-8" />
<body>
<div id="react-root"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-with-addons.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.7.7/babel.min.js"></script>
<script id="react-app" type="text/template">
const App = ({name}) => {
return <h1>Welcome to React, {name} !</h1>;
};
ReactDOM.render(<App name="Alain" />, document.getElementById("react-root"));
</script>
<script>
eval(Babel.transform(document.getElementById("react-app").innerHTML, {presets: ['es2015', 'react']}).code);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment