Skip to content

Instantly share code, notes, and snippets.

@arecvlohe
Last active Oct 22, 2017
Embed
What would you like to do?
esnextbin sketch
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>ESNextbin Sketch</title>
<!-- put additional styles and scripts here -->
</head>
<body>
<div id='root'></div>
</body>
</html>
import { default as React, Component } from 'react'
import { render } from 'react-dom'
import { compose } from 'recompose'
const container = endpoint => Presentational =>
class extends Component {
state = {
data: []
}
componentDidMount() {
fetch(endpoint)
.then(response => response.json())
.then(data => this.setState({ data }))
}
render() {
return <Presentational data={this.state.data} />
}
}
const Presentational = ({ data }) =>
<ul>{data.map((v, k) =>
<li key={k}>
{v.username}
</li>
)}
</ul>
const HigherOrderComponent = compose(
container('https://fcctop100.herokuapp.com/api/fccusers/top/alltime')
)
const FetchAndDisplayFCCData = HigherOrderComponent(Presentational)
render(<FetchAndDisplayFCCData />, document.querySelector('#root'))
{
"name": "esnextbin-sketch",
"version": "0.0.0",
"dependencies": {
"react": "15.3.2",
"react-dom": "15.3.2",
"recompose": "0.20.2",
"babel-runtime": "6.11.6"
}
}
'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');
var _recompose = require('recompose');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var container = function container(endpoint) {
return function (Presentational) {
return function (_Component) {
(0, _inherits3.default)(_class2, _Component);
function _class2() {
var _Object$getPrototypeO;
var _temp, _this, _ret;
(0, _classCallCheck3.default)(this, _class2);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = (0, _possibleConstructorReturn3.default)(this, (_Object$getPrototypeO = (0, _getPrototypeOf2.default)(_class2)).call.apply(_Object$getPrototypeO, [this].concat(args))), _this), _this.state = {
data: []
}, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
}
(0, _createClass3.default)(_class2, [{
key: 'componentDidMount',
value: function componentDidMount() {
var _this2 = this;
fetch(endpoint).then(function (response) {
return response.json();
}).then(function (data) {
return _this2.setState({ data: data });
});
}
}, {
key: 'render',
value: function render() {
return _react2.default.createElement(Presentational, { data: this.state.data });
}
}]);
return _class2;
}(_react.Component);
};
};
var Presentational = function Presentational(_ref) {
var data = _ref.data;
return _react2.default.createElement(
'ul',
null,
data.map(function (v, k) {
return _react2.default.createElement(
'li',
{ key: k },
v.username
);
})
);
};
var HigherOrderComponent = (0, _recompose.compose)(container('https://fcctop100.herokuapp.com/api/fccusers/top/alltime'));
var FetchAndDisplayFCCData = HigherOrderComponent(Presentational);
(0, _reactDom.render)(_react2.default.createElement(FetchAndDisplayFCCData, null), document.querySelector('#root'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment