🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

ib-image-optimizer

Package Overview
Dependencies
Maintainers
2
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ib-image-optimizer

A React component for optimizing images with loading states and aspect ratio control

1.9.2
latest
npm
Version published
Weekly downloads
615
998.21%
Maintainers
2
Weekly downloads
 
Created
Source

IB Image Optimizer

A React component for optimizing images with loading states and error handling.

Features

  • Image loading states with skeleton placeholders
  • Error handling with fallback images
  • Aspect ratio control
  • Next.js server component support
  • TypeScript support

Installation

npm install ib-image-optimizer

Usage

Basic Usage

import { ImageOptimizer } from "ib-image-optimizer/use-react";

function App() {
  return (
    <ImageOptimizer
      src="https://example.com/image.jpg"
      fallbackSrc="https://example.com/fallback.jpg"
      aspectRatio="square"
      onLoad={() => console.log("Image loaded")}
      onError={(error) => console.error("Image failed to load:", error)}
    />
  );
}

Next.js Integration

The component is designed to work seamlessly with Next.js server components:

// app/page.tsx
import { ImageOptimizer } from "ib-image-optimizer/use-react";

export default function Page() {
  return (
    <ImageOptimizer
      src="/images/hero.jpg"
      fallbackSrc="/images/fallback.jpg"
      aspectRatio="landscape"
    />
  );
}

Props

PropTypeDescription
srcstringThe source URL of the image
fallbackSrcstringFallback image URL to display if the main image fails to load
aspectRatio"auto" | "square" | "portrait" | "landscape"Controls the aspect ratio of the image container
onLoad() => voidCallback fired when the image loads successfully
onError(error: Error | ErrorEvent) => voidCallback fired when the image fails to load
classNamestringAdditional CSS classes to apply to the container
styleReact.CSSPropertiesInline styles to apply to the container
showSkeletonbooleanWhether to show a skeleton loading state (default: true)

Requirements

  • React 18.2.0 or higher
  • Next.js 14.0.0 or higher (for server component support)
  • TypeScript 4.9.0 or higher (recommended)

License

MIT

Contributing

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

Keywords

react

FAQs

Package last updated on 06 May 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts