Skip to content

Instantly share code, notes, and snippets.

Avatar

Ashok Rao ashokrao1

View GitHub Profile
@ashokrao1
ashokrao1 / app.js
Created Dec 19, 2017 — forked from acdlite/app.js
Quick and dirty code splitting with React Router v4
View app.js
// getComponent is a function that returns a promise for a component
// It will not be called until the first mount
function asyncComponent(getComponent) {
return class AsyncComponent extends React.Component {
static Component = null;
state = { Component: AsyncComponent.Component };
componentWillMount() {
if (!this.state.Component) {
getComponent().then(Component => {
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style id="jsbin-css">
*, *:before, *:after {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;