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 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-use-optimized-image

v1.0.2

Published

A React hook for image optimization (format detection, lazy loading, caching, CDN support)

Readme

🚀 React Use Optimized Image

A smart image optimization hook for React that improves performance by auto-detecting formats, lazy loading, caching, and optimizing based on network speed. 🎯

npm npm downloads MIT License


📦 Installation

npm install react-use-optimized-image
# or
yarn add react-use-optimized-image

🌟 Features & Benefits

Automatic Format Detection

  • Uses WebP / AVIF for supported browsers for better compression.
  • Falls back to JPEG / PNG for older browsers.
  • Saves bandwidth & improves Core Web Vitals (LCP, FCP).

🚀 Lazy Loading for Faster Performance

  • Uses IntersectionObserver to load images only when visible.
  • Reduces initial page load time and improves SEO.

💾 Smart Caching with Local Storage

  • Stores optimized image URLs in localStorage for instant reloads.
  • Reduces redundant requests, making browsing faster.

Network Speed Adaptation

  • Uses navigator.connection.effectiveType to adjust image quality:
    • Fast network → Loads high-resolution images.
    • Slow network (2G/3G) → Loads compressed images to improve speed.

🌍 CDN Support for Global Access

  • Supports Cloudinary, Imgix, and other CDNs.
  • Ensures faster load times for users worldwide.

🔧 Developer-Friendly API

  • Simple React hook-based API with TypeScript support.
  • Fully customizable with format, quality, and lazy load options.

🛠 Usage Examples (JSX)

📌 Basic JSX Example

import React from "react";
import { useOptimizedImage } from "react-use-optimized-image";

const ImageComponent = () => {
  const { optimizedSrc, isLoading, imgRef } = useOptimizedImage({
    src: "https://example.com/image.jpg",
    lazy: true,
  });

  return (
    <div>
      {isLoading ? (
        <p>Loading...</p>
      ) : (
        <img ref={imgRef} src={optimizedSrc} alt="Optimized" />
      )}
    </div>
  );
};

export default ImageComponent;

📌 TypeScript Example with Custom Props

import React from "react";
import { useOptimizedImage } from "react-use-optimized-image";

interface ImageProps {
  src: string;
  alt: string;
  quality?: number;
}

const OptimizedImage: React.FC<ImageProps> = ({ src, alt, quality = 80 }) => {
  const { optimizedSrc, isLoading, imgRef } = useOptimizedImage({
    src,
    quality,
  });

  return (
    <div>
      {isLoading ? (
        <p>Loading...</p>
      ) : (
        <img ref={imgRef} src={optimizedSrc!} alt={alt} />
      )}
    </div>
  );
};

export default OptimizedImage;

🔥 Advanced Use Cases

1️⃣ Optimizing Images with CDN

const { optimizedSrc } = useOptimizedImage({
  src: "https://res.cloudinary.com/demo/image/upload/sample.jpg",
  quality: 80,
  cdn: "cloudinary",
});

✅ Automatically formats URL for better compression & performance.

2️⃣ Caching for Faster Reloads

const { optimizedSrc } = useOptimizedImage({
  src: "https://example.com/image.jpg",
  cache: true,
});

✅ Minimizes redundant API calls, reducing server load.

3️⃣ Adaptive Quality Based on Network Speed

const { optimizedSrc } = useOptimizedImage({
  src: "https://example.com/image.jpg",
  adjustForNetwork: true,
});

✅ Ensures fast loading for all users, even on mobile networks.