Babel React template

Developer
Size
5,357 Kb
Views
14,168

How do I make an babel react template?

A very simple example for playing around with React. Includes transitions, fetching data, repetition and a stateless component.. What is a babel react template? How do you make a babel react template? This script and codes were developed by Ross B on 24 November 2022, Thursday.

Babel React template Previews

Babel React template - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Babel React template</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="app"></div> <script src='https://cdnjs.cloudflare.com/ajax/libs/react/0.14.0/react-with-addons.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/fetch/0.10.0/fetch.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Babel React template - Script Codes CSS Codes

.card { padding: 20px; border-bottom: 1px solid lightgray;
}
.card::after { clear: both; content: ""; display: table;
}
.card .card-thumbnail { float: left; margin-right: 20px; height: 150px; width: 150px;
}
.slide-enter { opacity: 0.01;
}
.slide-enter .card-thumbnail { -webkit-transform: translateX(-100%); transform: translateX(-100%);
}
.slide-enter.slide-enter-active { opacity: 1; -webkit-transition: opacity 500ms ease-in; transition: opacity 500ms ease-in;
}
.slide-enter.slide-enter-active .card-thumbnail { -webkit-transition: -webkit-transform 0.5s ease; transition: -webkit-transform 0.5s ease; transition: transform 0.5s ease; transition: transform 0.5s ease, -webkit-transform 0.5s ease; -webkit-transform: translateZ(0); transform: translateZ(0);
}
.slide-leave { opacity: 1;
}
.slide-leave.slide-leave-active { opacity: 0.01; -webkit-transition: opacity 300ms ease-in; transition: opacity 300ms ease-in;
}

Babel React template - Script Codes JS Codes

"use strict";
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; }
/*
** Data from 'http://jsonplaceholder.typicode.com/photos'
** JSON schema is as follows:
** [
** {
** "albumId": 1,
** "id": 1,
** "title": "accusamus beatae ad",
** "url": "http://placehold.it/600/92c952",
** "thumbnailUrl": "http://placehold.it/150/30ac17"
** },
** ...
** ]
*/
/*
** React Component, CSSTransitionGroup:
** This will be used to animate some DOM insertions
** by creating a container around the points at which
** nodes will be inserted [or removed].
*/
var CSSTransitionGroup = React.addons.CSSTransitionGroup;
// Source of data, we use fetch to retrieve the JSON
// fetch docs: https://github.com/github/fetch
var dataURL = 'http://jsonplaceholder.typicode.com/photos';
// Maximum number of items to show
var showNItems = 50;
/*
** React feature, stateless components:
** These components can be created with less code.
** Props can be picked through destructuring (seen below)
** or by passing a props object.
** The below example uses an implicit return, but you
** could do stuff before returning the component.
** These components do not have a state.
*/
var PreviewCard = function PreviewCard(_ref) { var title = _ref.title; var thumbnailUrl = _ref.thumbnailUrl; var url = _ref.url; var id = _ref.id; return React.createElement( "div", { className: "card", key: id }, React.createElement("img", { className: "card-thumbnail", src: thumbnailUrl }), React.createElement( "h3", { className: "card-title" }, title ), React.createElement( "span", null, "Full resolution: " ), React.createElement( "a", { href: url, target: "_blank" }, url ) );
};
/*
** Custom React component:
** This is our top level component.
** In more complex situations your uppermost
** component might be a router or some sort
** or Flux store interface which would wrap
** our App component.
*/
var App = function (_React$Component) { _inherits(App, _React$Component); function App() { _classCallCheck(this, App); var _this = _possibleConstructorReturn(this, _React$Component.call(this)); _this.state = { items: [] }; return _this; } App.prototype.componentDidMount = function componentDidMount() { var _this2 = this; fetch(dataURL).then(function (response) { return response.json(); }).then(function (body) { return _this2.setState({ items: body.slice(0, showNItems) }); }); }; App.prototype.render = function render() { var items = this.state.items.map(function (i) { return React.createElement(PreviewCard, i); }); return React.createElement( "div", null, items.length === 0 ? 'Loading...' : '', React.createElement( CSSTransitionGroup, { transitionName: "slide" }, items ) ); }; return App;
}(React.Component);
// Insertion point for App component
var entryNode = document.querySelector('.app');
// React API to render component into DOM
React.render(React.createElement(App, null), entryNode);
Babel React template - Script Codes
Babel React template - Script Codes
Home Page Home
Developer Ross B
Username rocbear
Uploaded November 24, 2022
Rating 3
Size 5,357 Kb
Views 14,168
Do you need developer help for Babel React template?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Ross B (rocbear) Script Codes
Create amazing sales emails with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!