- Notifications
You must be signed in to change notification settings - Fork0
Fast 1.15KB, Gzip 0.63KB, React Component to lazy load and other components/elements and use the Intersection Observer API.
jsdeveloperr/react-lazy-loader-component
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Fast 1.15KB, Gzip 0.63KB, React Component to lazy load and other components/elements and use theIntersection Observer API.
Check our 👉example
# install with npmnpm install react-lazy-loader-component# install with yarnyarn add react-lazy-loader-component# install with pnpmpnpm add react-lazy-loader-component
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>);
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>);
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>);
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>);
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>);
Type:ComponentType | keyof JSX.IntrinsicElements Default:div
Thetag option allows you to set the html element's tag even when it has no content.
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.
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.
Type:String
TheclassName option allows you to set the element's className even when it has no content.
Type:CSSProperties
Thestyle option allows you to set the element's style even when it has no content.
TypeBoolean
A Boolean to execute when the content appears on the screen.
pnpm buildcd examplepnpm devAbout
Fast 1.15KB, Gzip 0.63KB, React Component to lazy load and other components/elements and use the Intersection Observer API.
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.
