All Projects → robcalcroft → react-use-lazy-load-image

robcalcroft / react-use-lazy-load-image

Licence: MIT license
🌅 ⚡ Add image lazy loading to your React app with ease

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-use-lazy-load-image

Zsh Lazyload
zsh plugin for lazy load commands and speed up start up time of zsh
Stars: ✭ 33 (+153.85%)
Mutual labels:  lazyload
Douban Movie
🎥The douban-movie Application built with webpack + vue + vuex + vue-router + iView.
Stars: ✭ 147 (+1030.77%)
Mutual labels:  lazyload
React Progressive Loader
Utility to load images and React components progressively, and get code splitting for free
Stars: ✭ 224 (+1623.08%)
Mutual labels:  lazyload
Responsively Lazy
Lazy load responsive images
Stars: ✭ 1,080 (+8207.69%)
Mutual labels:  lazyload
React Lazy
Universal lazy loader components using IntersectionObserver for React
Stars: ✭ 118 (+807.69%)
Mutual labels:  lazyload
React In Viewport
Detect if React component is in viewport
Stars: ✭ 183 (+1307.69%)
Mutual labels:  lazyload
Ng Lazy Load
Lazy loading images with Angular.
Stars: ✭ 12 (-7.69%)
Mutual labels:  lazyload
Lazysizes
High performance and SEO friendly lazy loader for images (responsive and normal), iframes and more, that detects any visibility changes triggered through user interaction, CSS or JavaScript without configuration.
Stars: ✭ 15,716 (+120792.31%)
Mutual labels:  lazyload
Defer.js
🥇 A super small, super efficient library that helps you lazy load everything like images, video, audio, iframe as well as stylesheets, and JavaScript.
Stars: ✭ 138 (+961.54%)
Mutual labels:  lazyload
Lazyload Image
HTMLImageElement extension for lazy loading.
Stars: ✭ 208 (+1500%)
Mutual labels:  lazyload
Yall.js
A fast, flexible, and small SEO-friendly lazy loader.
Stars: ✭ 1,163 (+8846.15%)
Mutual labels:  lazyload
Androidxlazyload
😈😈Fragment lazy loading under the androix
Stars: ✭ 110 (+746.15%)
Mutual labels:  lazyload
Lazy Progressive Enhancement
A lazy image loader designed to enforce progressive enhancement and valid HTML.
Stars: ✭ 188 (+1346.15%)
Mutual labels:  lazyload
Jquery.lazy
A lightweight, fast, feature-rich, powerful and highly configurable delayed content, image and background lazy loading plugin for jQuery & Zepto.
Stars: ✭ 965 (+7323.08%)
Mutual labels:  lazyload
Oclazyload
Lazy load modules & components in AngularJS
Stars: ✭ 2,661 (+20369.23%)
Mutual labels:  lazyload
Vue Lazy Component
🐌 Vue.js 2.x 组件级懒加载方案-Vue.js 2.x component level lazy loading solution
Stars: ✭ 915 (+6938.46%)
Mutual labels:  lazyload
Ng In Viewport
Allows us to check if an element is within the browsers visual viewport
Stars: ✭ 178 (+1269.23%)
Mutual labels:  lazyload
angular-webpack-material-lazyload-typescript-starter-template
Angular starter template using typescript, angular-material, ui-router, oclazyload with webpack support.
Stars: ✭ 55 (+323.08%)
Mutual labels:  lazyload
Vue Lazyload Img
A plugin of vue for image lazyload(vue图片懒加载插件)
Stars: ✭ 250 (+1823.08%)
Mutual labels:  lazyload
Taro Listview
taro框架长列表方案 :集成下拉刷新、骨架屏、无限滚动、图片懒加载;
Stars: ✭ 197 (+1415.38%)
Mutual labels:  lazyload

react-use-lazy-load-image 🌅

Add image lazy loading to your React app with ease

react-use-lazy-load-image uses the IntersectionObserver to provide a performant solution to lazy loading images that doesn't involve scroll event listeners. The IntersectionObserver API is still quite new so older browsers may not support this, however there are some good polyfills available for these use cases.

react-use-lazy-load-image is super light weight so won't add any extra bulk to your app.

As the name suggests react-use-lazy-load-image uses React Hooks, so you need to be using React function components to use this library.

Usage

  1. Add a data-img-src attribute (you can customise this) to your img tags as your main image source
  2. Change the src attribute to a placeholder like a small data URL blob
  3. Import and run useLazyLoadImage in the body of your React function component

Now as your users scroll down the page the images will load just in time.

Arguments

Argument name Default value Description
imageAttribute '[data-img-src]' The query passed to document.querySelectorAll to grab all lazy load-able images on the page
imageAttributeKey 'imgSrc' The camel-cased key to pull the data-img-src out of the image element
rootMargin '200px 0px' https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#Intersection_observer_options
threshold 0.01 https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#Intersection_observer_options
debug false When set to true some useful messages will get logged to the console
dependencies [] React useEffect dependency array, used for re-running this logic if the component re-renders and the img references change (read more about conditionally firing an effect)

Example

import React from 'react';
import useLazyLoadImage from 'react-use-lazy-load-image';

function App() {
  useLazyLoadImageReact();

  return (
    <div>Lots of content that means the image is off screen goes here</div>
    <img src="DATA URL" data-img-src="https://link-to-my-image.com/image.png" alt="My image" />
  )
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].