useimageloadstate
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

useImageLoadState 🖼

bundlephobia npm version

A simple React hook for listening to image load/error states

useImageLoadState is a reusable hook that listens for load and error events on given image, and returns their current state. This allows you to implement functionaility based on the image state without having to rewrite callbacks and event listeners each time.

Features

  • Lightweight < 468B
  • Unsubscribes all event listeners when the hook is unmounted
  • Written and typed with TypeScript

Usage

import useImageLoadState from "useimageloadstate";

const image = 'https://www.fillmurray.com/460/300';
const { hasLoaded, hasError, isFetching } = useImageLoadState(image);

Return values

  • hasLoaded - boolean - loading state of the image
  • hasError - boolean - error state of the image
  • isFetching - boolean - fetching state of the image
  • image - string - the image original image url

Readme

Keywords

none

Package Sidebar

Install

npm i useimageloadstate

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

23.8 kB

Total Files

19

Last publish

Collaborators

  • kwaimind