Skip to content

frzkn/use-images-loaded

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🖼️ useImagesLoaded

Custom react hook which returns true once all the images inside a container are loaded.

Check out a working demo here

🚀 Getting Started

Installation

yarn add use-images-loaded

Usage

Displaying a loading indicator while images are loading in a container

import useImageLoaded from 'use-images-loaded'

const ImageContainer = () => {
  const [ref, loaded] = useImagesLoaded()

  return (
    <div ref={ref}>
    <p> Status: {loaded ? 'Loaded': 'Loading'} </p>
    <img src="https://unsplash.it/200/200" alt="image"/>
    <img src="https://unsplash.it/200/200" alt="image"/>
    <img src="https://unsplash.it/200/200" alt="image"/>
    </div>
  )
}

About

🖼️ Returns true once all the images inside a container are loaded

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published