Skip to content

Instantly share code, notes, and snippets.

@noateden
Created August 5, 2018 08:03
Show Gist options
  • Save noateden/713c4e64c3b513b6bb53dad1c0bf16ba to your computer and use it in GitHub Desktop.
Save noateden/713c4e64c3b513b6bb53dad1c0bf16ba to your computer and use it in GitHub Desktop.
Get started with ReacJS
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Getting started with ReactJS</title>
</head>
<body>
<-- Create a button -->
<div id="like_button_container"></div>
<-- Add ReactJS -->
<script src="https://unpkg.com/react@16/umd/react.production.min.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js" crossorigin></script>
<-- Add our script file -->
<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');
ReactDOM.render(e(LikeButton), domContainer);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment