Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Fast 1.15KB, Gzip 0.63KB, React Component to lazy load and other components/elements and use the Intersection Observer API.

NotificationsYou must be signed in to change notification settings

jsdeveloperr/react-lazy-loader-component

Repository files navigation


logo

🔥 React Lazy Loader Component 🔥

npmnpm bundle sizenpmGitHub license

📚 Introduction

Fast 1.15KB, Gzip 0.63KB, React Component to lazy load and other components/elements and use theIntersection Observer API.

🚀 Example

Check our 👉example

📦 Installation

# install with npmnpm install react-lazy-loader-component# install with yarnyarn add react-lazy-loader-component# install with pnpmpnpm add react-lazy-loader-component

🚀 Example Repo

📦 Examples

🗂 Basic Usage

importReactfrom"react";import{LazyLoad}from"react-lazy-loader-component";constMyComponent=()=>(<LazyLoad><imgsrc="https://images.pexels.com/photos/3748221/pexels-photo-3748221.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1"/></LazyLoad>);

🗂 Loading the image 100px prior to scroll

import{LazyLoad}from"react-lazy-loader-component";constMyComponent=()=>(<LazyLoadrootMargin={100}><imgsrc="https://images.pexels.com/photos/3748221/pexels-photo-3748221.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1"/></LazyLoad>);

🗂 Loading image only when 15% of it is in the viewport.

import{LazyLoad}from"react-lazy-loader-component";constMyComponent=()=>(<LazyLoadrootMargin={100}threshold={0.95}><imgsrc="https://images.pexels.com/photos/3748221/pexels-photo-3748221.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1"/></LazyLoad>);

🗂 Performing a side effect once your image is loaded

import{LazyLoad}from"react-lazy-loader-component";constMyComponent=()=>(<LazyLoadrootMargin={400}threshold={0.95}freezeOnceVisible={true}><imgsrc="https://images.pexels.com/photos/3748221/pexels-photo-3748221.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1"/></LazyLoad>);

🗂 Suspense and Lazy import

importReact,{Suspense}from"react";import{LazyLoad}from"react-lazy-loader-component";constMyComponent=()=>(<Suspensefallback={<div>Loading...</div>}><LazyLoadrootMargin={100}><imgsrc="https://images.pexels.com/photos/3748221/pexels-photo-3748221.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1"/></LazyLoad></Suspense>);

🎉 Props

✏️ tag

Type:ComponentType | keyof JSX.IntrinsicElements Default:div

Thetag option allows you to set the html element's tag even when it has no content.

✏️ rootMargin

Type:String Default:0%

TherootMargin option allows you to specify how far below, above, to the left, and to the right of the viewport you want tobegin displaying your content. If you specify0, your content will be displayed as soon as it is visible in the viewport, if you want to load100px below or above the viewport, use100.

✏️ threshold

Type:number | number[] Default:0

Thisthreshold option allows you to specify how much of the element must be shown on the screen prior to loading. This requires awidth andheight to be set on the<LazyLoad> component in order for the browser to calcualte the viewable area.

✏️ className

Type:String

TheclassName option allows you to set the element's className even when it has no content.

✏️ style

Type:CSSProperties

Thestyle option allows you to set the element's style even when it has no content.

✏️ freezeOnceVisible

TypeBoolean

A Boolean to execute when the content appears on the screen.

🔥 Building LazyLoad

pnpm build

🌈 Running examples

cd examplepnpm dev

📄 License

🍁 MIT Licensed | Copyright © 2022-present Abdulnasır Olcan and @ReactLazyLoadComponent contributors

Back To The Top

About

Fast 1.15KB, Gzip 0.63KB, React Component to lazy load and other components/elements and use the Intersection Observer API.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp