Skip to content

Instantly share code, notes, and snippets.

@parvezk
Created August 25, 2016 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parvezk/f8f9a17af9cc5378336142168281a3e2 to your computer and use it in GitHub Desktop.
Save parvezk/f8f9a17af9cc5378336142168281a3e2 to your computer and use it in GitHub Desktop.
esnextbin sketch
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>ESNextbin Sketch</title>
<!-- put additional styles and scripts here -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.0.1/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.0.1/react-dom.js"></script>
</head>
<body>
<!-- put markup and other contents here -->
<h1>React Sketch</h1>
<div id="sketch"></div>
</body>
</html>
// write ES2015 code and import modules from npm
// and then press "Execute" to run your program
var Sketch = React.createClass({
getInitialState: function() {
return {x: 50, y: 50};
},
handleMouseMove: function(event) {
this.setState({
x: event.clientX,
y: event.clientY
});
},
render: function() {
return (
<svg width="640" height="480" onMouseMove={this.handleMouseMove}>
<circle cx={this.state.x} cy={this.state.y} r="40"
stroke="black" fill="white"/>
</svg>
);
}
});
ReactDOM.render(
<Sketch/>,
document.getElementById('sketch')
);
{
"name": "esnextbin-sketch",
"version": "0.0.0"
}
"use strict";
// write ES2015 code and import modules from npm
// and then press "Execute" to run your program
var Sketch = React.createClass({
displayName: "Sketch",
getInitialState: function getInitialState() {
return { x: 50, y: 50 };
},
handleMouseMove: function handleMouseMove(event) {
this.setState({
x: event.clientX,
y: event.clientY
});
},
render: function render() {
return React.createElement(
"svg",
{ width: "640", height: "480", onMouseMove: this.handleMouseMove },
React.createElement("circle", { cx: this.state.x, cy: this.state.y, r: "40",
stroke: "black", fill: "white" })
);
}
});
ReactDOM.render(React.createElement(Sketch, null), document.getElementById('sketch'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment