0.1.6 • Published 7 years ago

react-lazify v0.1.6

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

Lazify

Lazy load for react components. Original idea found here.

Install

yarn add react-lazify --save

or

npm install react-lazify --save

How to use

Example 1:

import lazify from 'react-lazify';

const loadComponent = (name) => lazify(() => System.import(`pages/${name}.jsx`));

// ...
// render()

<Router>
    <div>
        <Route exact path="/" component={ loadComponent('Home') }/>
        <Route path="/settings" component={ loadComponent('Settings') }/>
    </div>
</Router>

System.import is a Webpack function that can load chunks. Also webpack can automatically generate a chunks that had dynamic names.

Example 2:

import lazify from 'react-lazify';

const MyComponent = lazify(() => System.import('components/MyComponent.jsx'), <Spinner />);

// ...
// render()

<MyComponent some={ 'prop' } that={ 'will' } be={ 'passed' } to={ 'loaded' } component />

Here we pass second optional argument to function lazify(load, [prompt]), that will be display during component loading.

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago