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 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-img-toolkit

v1.1.5

Published

A lightweight React library for optimizing image loading through preloading, lazy loading, and caching capabilities

Readme

React Image Toolkit

A lightweight React library for optimizing image loading through preloading, lazy loading, and caching capabilities.

Features

  • 🚀 Image Preloading: Load images in advance for instant display
  • 🎯 Lazy Loading: Load images only when they enter the viewport
  • 💾 Image Caching: Cache images for faster subsequent loads
  • 📊 Status Tracking: Monitor image loading states
  • 🎨 TypeScript Support: Full TypeScript support with type definitions
  • 🪶 Lightweight: No external dependencies except React

Installation

npm install react-img-toolkit

Usage

Image Preloader Component

data can be any structured, ImagePreloader will extract image URLs from it.

import { ImagePreloader } from 'react-img-toolkit';

function Gallery() {
   const data = {
      images: [
         'https://example.com/image1.jpg',
         'https://example.com/image2.jpg',
      ],
      otherData: 'Hello World!',
   };

   return (
    <ImagePreloader
      data={data}
      onSuccess={() => console.log('All images loaded!')}
      onError={(error) => console.error('Failed to load:', error)}
    >
      {/* Your gallery content */}
    </ImagePreloader>
  );
}

Hooks

useImagePreloader

Preload multiple images and track their loading status:

import { useImagePreloader } from 'react-img-toolkit';

function Gallery() {
  const { imageUrls, count } = useImagePreloader([
    'https://example.com/image1.jpg',
    'https://example.com/image2.jpg'
  ]);

  return (
    <div>
      <p>Loaded {count} images</p>
      {imageUrls.map((url, index) => (
        <img key={index} src={url} alt={`Image ${index + 1}`} />
      ))}
    </div>
  );
}

useLazyImage

Load images only when they enter the viewport:

import { useLazyImage } from 'react-img-toolkit';

function LazyImage() {
  const { ref, isIntersecting, isLoaded } = useLazyImage(
    'https://example.com/large-image.jpg',
    {
      threshold: 0.1,
      rootMargin: '50px'
    }
  );

  return (
    <div ref={ref}>
      {isLoaded && (
        <img src="https://example.com/large-image.jpg" alt="Lazy loaded" />
      )}
    </div>
  );
}

useImageCache

Cache images for faster subsequent loads:

import { useImageCache } from 'react-img-toolkit';

function CachedImage() {
  const { cachedSrc, loading, isCached } = useImageCache(
    'https://example.com/image.jpg'
  );

  if (loading) return <div>Loading...</div>;

  return <img src={cachedSrc} alt="Cached image" />;
}

useImageStatus

Track the loading status of an image:

import { useImageStatus } from 'react-img-toolkit';

function ImageWithStatus() {
  const status = useImageStatus('https://example.com/image.jpg');

  return (
    <div>
      <p>Status: {status}</p>
      {status === 'loaded' && (
        <img src="https://example.com/image.jpg" alt="Status tracked" />
      )}
    </div>
  );
}

API Reference

ImagePreloader Component

| Prop | Type | Description | |-----------|------------------------|-------------------------------------| | data | any | Any structured data. | | onSuccess | () => void | Callback when all images are loaded | | onError | (error: Error) => void | Callback when an error occurs | | children | ReactNode | Content to render |

useImagePreloader Hook

function useImagePreloader(
  urls: string[],
  options?: {
    onSuccess?: () => void;
    onError?: (error: Error) => void;
  }
): {
  imageUrls: string[];
  count: number;
};

useLazyImage Hook

function useLazyImage(
  src: string,
  options?: {
    threshold?: number;
    rootMargin?: string;
  }
): {
  ref: RefObject<HTMLElement>;
  isIntersecting: boolean;
  isLoaded: boolean;
};

useImageCache Hook

function useImageCache(
  src: string
): {
  cachedSrc: string | null;
  loading: boolean;
  isCached: boolean;
};

useImageStatus Hook

function useImageStatus(
  src: string
): 'idle' | 'loading' | 'loaded' | 'error';

Development

  1. Clone the repository:
    git clone https://github.com/IxtiyorDeveloper/react-img-toolkit.git
    cd react-img-toolkit
  2. Install dependencies:
    npm install
  3. Start development server:
    npm run dev
  4. Run tests:
    npm test

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT