Last active
April 8, 2017 02:17
-
-
Save davelnewton/495104605f24c588624f5b169075c091 to your computer and use it in GitHub Desktop.
React createClass?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import ReactDOM from 'react-dom'; | |
class Counter extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
count: 1 | |
} | |
} | |
componentDidMount() { | |
setInterval( ()=> { | |
this.setState((prevState, props) => ({ | |
count: prevState.count + 1 | |
})) | |
}, 1000) | |
} | |
render(){ | |
return ( | |
<h1>{this.state.count}</h1> | |
) | |
} | |
} | |
const root = document.createElement('div'); | |
root.id = 'app'; | |
document.body.appendChild(root); | |
ReactDOM.render( | |
<Counter />, | |
document.querySelector('#app') | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | |
var _react = require('react'); | |
var _react2 = _interopRequireDefault(_react); | |
var _reactDom = require('react-dom'); | |
var _reactDom2 = _interopRequireDefault(_reactDom); | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | |
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | |
var Counter = function (_React$Component) { | |
_inherits(Counter, _React$Component); | |
function Counter(props) { | |
_classCallCheck(this, Counter); | |
var _this = _possibleConstructorReturn(this, (Counter.__proto__ || Object.getPrototypeOf(Counter)).call(this, props)); | |
_this.state = { | |
count: 1 | |
}; | |
return _this; | |
} | |
_createClass(Counter, [{ | |
key: 'componentDidMount', | |
value: function componentDidMount() { | |
var _this2 = this; | |
setInterval(function () { | |
_this2.setState(function (prevState, props) { | |
return { | |
count: prevState.count + 1 | |
}; | |
}); | |
}, 1000); | |
} | |
}, { | |
key: 'render', | |
value: function render() { | |
return _react2.default.createElement( | |
'h1', | |
null, | |
this.state.count | |
); | |
} | |
}]); | |
return Counter; | |
}(_react2.default.Component); | |
var root = document.createElement('div'); | |
root.id = 'app'; | |
document.body.appendChild(root); | |
_reactDom2.default.render(_react2.default.createElement(Counter, null), document.querySelector('#app')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | |
var _react = require('react'); | |
var _react2 = _interopRequireDefault(_react); | |
var _reactDom = require('react-dom'); | |
var _reactDom2 = _interopRequireDefault(_reactDom); | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | |
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | |
var Counter = function (_React$Component) { | |
_inherits(Counter, _React$Component); | |
function Counter(props) { | |
_classCallCheck(this, Counter); | |
var _this = _possibleConstructorReturn(this, (Counter.__proto__ || Object.getPrototypeOf(Counter)).call(this, props)); | |
_this.state = { | |
count: 1 | |
}; | |
return _this; | |
} | |
_createClass(Counter, [{ | |
key: 'componentDidMount', | |
value: function componentDidMount() { | |
var _this2 = this; | |
setInterval(function () { | |
_this2.setState(function (prevState, props) { | |
return { | |
count: prevState.count + 1 | |
}; | |
}); | |
}, 1000); | |
} | |
}, { | |
key: 'render', | |
value: function render() { | |
return _react2.default.createElement( | |
'h1', | |
null, | |
this.state.count | |
); | |
} | |
}]); | |
return Counter; | |
}(_react2.default.Component); | |
var root = document.createElement('div'); | |
root.id = 'app'; | |
document.body.appendChild(root); | |
_reactDom2.default.render(_react2.default.createElement(Counter, null), document.querySelector('#app')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment