Skip to content

Instantly share code, notes, and snippets.

@joakin
Last active November 14, 2017 11:30
Show Gist options
  • Save joakin/eaae92a9e192f4bdff4161201eee2d6d to your computer and use it in GitHub Desktop.
Save joakin/eaae92a9e192f4bdff4161201eee2d6d to your computer and use it in GitHub Desktop.
Standalone React CDN HTML file
<!doctype html>
<html>
<head>
<title>React from CDN Demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}
</style>
</head>
<body>
<div id="root"></div>
<script crossorigin src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
<script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>
<script type="text/babel">
class App extends React.Component {
state = { time: 0 }
componentDidMount() {
this.setTime()
this.interval = setInterval(this.setTime, 1000)
}
componentWillUnmount() {
this.clearInterval(this.interval)
}
setTime = () => {
this.setState(({time}) => ({ time: time + 1 }))
}
render() {
return (
<div>
<h1>Hello World</h1>
<p>{this.state.time} seconds here!</p>
</div>
)
}
}
ReactDOM.render(<App />, document.getElementById('root'))
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment