Skip to content

About

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

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

17 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Contributors

Languages