Skip to content

Instantly share code, notes, and snippets.

@pcstout
Created November 8, 2016 22:33
Show Gist options
  • Save pcstout/035207b9f12ebc122638bf1338ba57b1 to your computer and use it in GitHub Desktop.
Save pcstout/035207b9f12ebc122638bf1338ba57b1 to your computer and use it in GitHub Desktop.
React example with all code in a single HTML file
<html>
<head>
<script src="https://jspm.io/system@0.19.js"></script>
<script type="text/template" id="code">
import React from 'react';
import ReactDOM from 'react-dom';
const Hello = ({name}) => <h1>Hello {name}!</h1>;
ReactDOM.render(
<Hello name={"Albert"}/>,
document.body.appendChild(document.createElement("div"))
);
</script>
</head>
<body>
<div id="container"></div>
<script type="text/javascript">
(function () {
System.config({
transpiler: 'babel',
babelOptions: {}
});
const tag = document.querySelector('#code'),
code = tag.textContent;
System.define(System.normalizeSync('my-module'), code);
System.import('my-module').then((mod) => {
console.log('mod loaded:', mod);
});
})();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment