npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-lazy-loader-component

v0.1.3

Published

react lazy loader component

Downloads

46

Readme

npm npm bundle size npm GitHub license

:books: Introduction

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

:rocket: Example

Check our 👉 example

:package: Installation

# install with npm
npm install react-lazy-loader-component
# install with yarn
yarn add react-lazy-loader-component
# install with pnpm
pnpm add react-lazy-loader-component

:rocket: Example Repo

📦 Examples

🗂 Basic Usage

import React from "react";
import { LazyLoad } from "react-lazy-loader-component";

const MyComponent = () => (
  <LazyLoad>
    <img src="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";

const MyComponent = () => (
  <LazyLoad rootMargin={100}>
    <img src="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";

const MyComponent = () => (
  <LazyLoad rootMargin={100} threshold={0.95}>
    <img src="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";

const MyComponent = () => (
  <LazyLoad rootMargin={400} threshold={0.95} freezeOnceVisible={true}>
    <img src="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

import React, { Suspense } from "react";
import { LazyLoad } from "react-lazy-loader-component";

const MyComponent = () => (
  <Suspense fallback={<div>Loading...</div>}>
    <LazyLoad rootMargin={100}>
      <img src="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

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

✏️ rootMargin

Type: String Default: 0%

The rootMargin option allows you to specify how far below, above, to the left, and to the right of the viewport you want to begin displaying your content. If you specify 0, your content will be displayed as soon as it is visible in the viewport, if you want to load 100px below or above the viewport, use 100.

✏️ threshold

Type: number | number[] Default: 0

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

✏️ className

Type: String

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

✏️ style

Type: CSSProperties

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

✏️ freezeOnceVisible

Type Boolean

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

🔥 Building LazyLoad

pnpm build

🌈 Running examples

cd example
pnpm dev

📄 License


Back To The Top