Skip to content

Instantly share code, notes, and snippets.

@phaistonian
Created April 22, 2016 14:59
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 phaistonian/4874139da0d7b341fb1ff29fc074d81f to your computer and use it in GitHub Desktop.
Save phaistonian/4874139da0d7b341fb1ff29fc074d81f 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 -->
</head>
<body>
<!-- put markup and other contents here -->
<div id="root"></div>
</body>
</html>
import React, { Component } from 'react';
import { render } from 'react-dom';
class Child extends Component {
constructor (props) {
super(props);
console.log('constructor');
}
componentWillMount () {
console.log('component will mount');
}
componentWillUnmount () {
console.log('component will Unmount');
}
componentWillReceiveProps () {
console.log('component will receive props');
}
render () {
return (
<p>{this.props.value}</p>
);
}
}
class Container extends Component {
constructor (props) {
super(props);
this.state = {
value: 1
};
}
render () {
return (
<div>
{this.state.value % 4
? <Child value={this.state.value} />
: null
}
<button onClick={() => this.setState({ value: this.state.value + 1})}>add</button>
</div>
);
}
}
render(<Container />, root);
{
"name": "esnextbin-sketch",
"version": "0.0.0",
"dependencies": {
"react": "0.14.8",
"react-dom": "0.14.8",
"babel-runtime": "6.6.1"
}
}
'use strict';
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _reactDom = require('react-dom');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var Child = (function (_Component) {
(0, _inherits3.default)(Child, _Component);
function Child(props) {
(0, _classCallCheck3.default)(this, Child);
var _this = (0, _possibleConstructorReturn3.default)(this, (0, _getPrototypeOf2.default)(Child).call(this, props));
console.log('constructor');
return _this;
}
(0, _createClass3.default)(Child, [{
key: 'componentWillMount',
value: function componentWillMount() {
console.log('component will mount');
}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
console.log('component will Unmount');
}
}, {
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps() {
console.log('component will receive props');
}
}, {
key: 'render',
value: function render() {
return _react2.default.createElement(
'p',
null,
this.props.value
);
}
}]);
return Child;
})(_react.Component);
var Container = (function (_Component2) {
(0, _inherits3.default)(Container, _Component2);
function Container(props) {
(0, _classCallCheck3.default)(this, Container);
var _this2 = (0, _possibleConstructorReturn3.default)(this, (0, _getPrototypeOf2.default)(Container).call(this, props));
_this2.state = {
value: 1
};
return _this2;
}
(0, _createClass3.default)(Container, [{
key: 'render',
value: function render() {
var _this3 = this;
return _react2.default.createElement(
'div',
null,
this.state.value % 4 ? _react2.default.createElement(Child, { value: this.state.value }) : null,
_react2.default.createElement(
'button',
{ onClick: function onClick() {
return _this3.setState({ value: _this3.state.value + 1 });
} },
'add'
)
);
}
}]);
return Container;
})(_react.Component);
(0, _reactDom.render)(_react2.default.createElement(Container, null), root);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment