twobin /react-lazyload

Lazy load your component, image or anything matters the performance.

★ 5,885⑂ 482👁 48⑃ 140● 277▤ 0
JavaScriptMITCreated 2015-08-07
+0
日增长
5,885
stars
482
forks
48
watchers
140
prs
277
issues
0
releases

README

Note

This project is now currently maintained by 
@ameerthehacker, please reach out to him on any issues or help.

----

 react-lazyload    

Lazyload your Components, Images or anything matters the performance.



Demo

 Why it's better

 - Take performance in mind, only 2 event listeners for all lazy-loaded components
 - Support both one-time lazy load and continuous lazy load mode
 - scroll / resize event handler is throttled so you won't suffer frequent update, you can switch to debounce mode too
 - Decorator supported
 - Server Side Rendering friendly
 - Thoroughly tested

 Installation

 2.0.0 is finally out, read Upgrade Guide, it's almost painless to upgrade!
 3.0.0 fixes the findDomNode warning through usage of React ref, and the following are the changes you need to be aware of

 Now we have an extra div wrapping the lazy loaded component for the React ref to work 
 We can understand that it is an extra DOM node, and we are working to optimize that if possible
 It might break your UI or snapshot tests based on your usage
 To customize the styling to the extra div please refer here
 Found any other problem, please feel free to leave a comment over here


$ npm install --save react-lazyload


 Usage

javascript
import React from 'react';
import ReactDOM from 'react-dom';
import LazyLoad from 'react-lazyload';
import MyComponent from './MyComponent';

const App = () = {
  return (
    
      
         /
                                  Lazy loading images is supported out of box,
                                  no extra config needed, set height for better
                                  experience
                                 /
      
      
                                / Once this component is loaded, LazyLoad will
                                 not care about it anymore, set this to true
                                 if you're concerned about improving performance /
        
      
      
                              / This component will be loaded when it's top
                                 edge is 100px from viewport. It's useful to
                                 make user ignorant about lazy load effect. /
        
      
      
        
      
    
  );
};

ReactDOM.render(, document.body);


If you want to have your component lazyloaded by default, try this handy decorator:

javascript
import { lazyload } from 'react-lazyload';

@lazyload({
  height: 200,
  once: true,
  offset: 100
})
class MyComponent extends React.Component {
  render() {
    return this component is lazyloaded by default!;
  }
}


 Special Tips

You should be aware that your component will only be mounted when it's visible in viewport, before that a placeholder will be rendered.

So you can safely send request in your component's componentDidMount without worrying about performance loss or add some pretty entering effects, see this demo for more detail.

 Props

 children

Type: Node Default: undefined

NOTICE
Only one child is allowed t

Top issues

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON