Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Tom910/react-async-loading

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

React Async Loading

import { asyncComponent } from 'react-async-loading';
// And export module...
export default asyncComponent(() => System.import('./Link.js'));

Code splitting to React and Webpack

Install

  • Install the module: npm install --save react-async-loading
  • Add plugin to you Webpack config:
new webpack.optimize.CommonsChunkPlugin({
  children: true, // necessary for splitting children chunks
  async: true // necessary for async loading chunks
})

Example

API

asyncComponent

Usage

asyncComponent(() => System.import('./Link.js'), { placeholder: <div>Loading</div> })

or

asyncComponent(() => require.ensure([], (require) => require('./Button.js'), 'Button'), { placeholder: <div>Loading</div> })

Props

- 1 argument

Required. There should be a function of the module is loaded. Webpack supports two varieties of modules. SystemJS and require.ensure. The only difference is in the syntax, and that you can specify the name of the chunk in require.ensure

  • System.import('./Link.js')
  • require.ensure([], (require) => require('./Button.js'), 'Button')

Webpack compiles

  • 0.chunk.js - numbers name in SystemJS
  • Button.chunk.js - we set the name in require.ensure
- 2 argument

Setting options. Now available placeholder option, which displays the item is loaded chunk

About

Code splitting to React and Webpack

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.