All Projects → saitolume → use-lazyload-ref

saitolume / use-lazyload-ref

Licence: MIT license
🖼️ Custom hook to use lazyload easily

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to use-lazyload-ref

Vue Lazyload Img
A plugin of vue for image lazyload(vue图片懒加载插件)
Stars: ✭ 250 (+331.03%)
Mutual labels:  lazyload
use-async-resource
A custom React hook for simple data fetching with React Suspense
Stars: ✭ 92 (+58.62%)
Mutual labels:  custom-hook
cms-fe-angular8
A Content Management System with Angular8, UI use Ant-Design(ng-zorro-antd)
Stars: ✭ 65 (+12.07%)
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 (-5.17%)
Mutual labels:  lazyload
lazy-load-images.js
Progressive & lazy loading images.
Stars: ✭ 17 (-70.69%)
Mutual labels:  lazyload
loadeer
🦌 Tiny, performant, SEO-friendly lazy loading library
Stars: ✭ 30 (-48.28%)
Mutual labels:  lazyload
React Progressive Loader
Utility to load images and React components progressively, and get code splitting for free
Stars: ✭ 224 (+286.21%)
Mutual labels:  lazyload
youtube-lazyload
LazyLoad Embed YouTube Player - simple and lightweight plugin - pure JavaScript
Stars: ✭ 23 (-60.34%)
Mutual labels:  lazyload
rocket-lazy-load
Standalone LazyLoad plugin for WordPress (based on WP Rocket)
Stars: ✭ 25 (-56.9%)
Mutual labels:  lazyload
zsh-lazyenv
Environments for lazy load commands and speed up start up time of zsh
Stars: ✭ 16 (-72.41%)
Mutual labels:  lazyload
react-use-lazy-load-image
🌅 ⚡ Add image lazy loading to your React app with ease
Stars: ✭ 13 (-77.59%)
Mutual labels:  lazyload
guide-to-async-components
📖 Guide To JavaScript Async Components
Stars: ✭ 79 (+36.21%)
Mutual labels:  lazyload
LazyHTML
LazyHTML is an OpenSource Javascript Library that Supports Lazy Loading of any elements without Modifying Code, LazyHTML can lazy load Ads, Videos, Images, Widgets, Javascript, CSS, Inline-Javascript, Inline-CSS & Any HTML.
Stars: ✭ 47 (-18.97%)
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 (+26996.55%)
Mutual labels:  lazyload
lazysimon
Minimal effort 350 byte JavaScript library to lazy load all <img> on your website
Stars: ✭ 18 (-68.97%)
Mutual labels:  lazyload
Oclazyload
Lazy load modules & components in AngularJS
Stars: ✭ 2,661 (+4487.93%)
Mutual labels:  lazyload
raf-pool
requestAnimationFrame pool to avoid busyness on the thread
Stars: ✭ 16 (-72.41%)
Mutual labels:  lazyload
useCustomHooks
📦 npm package containing a set of custom hooks for your next React project.
Stars: ✭ 12 (-79.31%)
Mutual labels:  custom-hook
lazyload-vue
Vue Plugin for vanilla-lazyload
Stars: ✭ 29 (-50%)
Mutual labels:  lazyload
react-class-hooks
React Hooks implementation for Class Components. Support React >= 15.3.2
Stars: ✭ 63 (+8.62%)
Mutual labels:  custom-hook

use-lazyload-ref

GitHub license npm version CI Status

Custom hook to use lazyload easily

Installation

$ npm install use-lazyload-ref
$ yarn add use-lazyload-ref

Usage

To enable lazy loading, simply specify ref and data-src attributes.

import React from 'react'
import useLazyloadRef from 'use-lazyload-ref'

const Component = ({ url }) => {
  const [ref, hasLoaded] = useLazyloadRef()

  return (
    <div>
      {hasLoaded || <Skeleton />}
      <img ref={ref} data-src={url} />
      {/* <audio ref={ref} data-src={url} />*/}
      {/* <iframe ref={ref} data-src={url} />*/}
      {/* <video ref={ref} data-src={url} />*/}
      {/* <div style={{ backgroundImage: `url(${url})` }}></div>*/}
    </div>
  )
}

API

useLazyloadRef: () => [(node: HTMLElement | null) => void, boolean]

Custom hook. In addition to src in audio, iframe, img and video, CSS property background-image can be lazy loaded.

const [ref, hasLoaded] = useLazyloadRef()

useLazyloadRef returns a callback ref function and a load state.

  • ref: Initialize observer for lazyload.
  • hasLoaded: Default is false. Turn true if the source has finished loading.

License

MIT

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].