Skip to content

Instantly share code, notes, and snippets.

@jondcallahan
Created October 16, 2020 18:26
Show Gist options
  • Save jondcallahan/6bd0f800b7fe32ec5d42ffb1fc0b26a9 to your computer and use it in GitHub Desktop.
Save jondcallahan/6bd0f800b7fe32ec5d42ffb1fc0b26a9 to your computer and use it in GitHub Desktop.
React + JSX in HTML file
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Hello World</title>
<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
class Main extends React.Component {
state = {
count: 0
}
handleIncrement = () => {
this.setState(prevState => ({count: prevState.count + 1}));
}
handleDecrement = () => {
this.setState(prevState => ({count: prevState.count - 1}));
}
render() {
return (
<>
<p>The count is: {this.state.count}</p>
<button onClick={this.handleIncrement}>+</button>
<button onClick={this.handleDecrement}>-</button>
</>
)
}
}
function MyComp() {
return <h1>Hello, jsx!</h1>
}
ReactDOM.render(
<Main/>,
document.getElementById('root')
);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment