Skip to main content


A hook for pre-loading image assets in the browser.

Concurrent Mode

This hook requires the use of React 18 in your project. It is also recommend that you use the "concurrent mode" feature for a better overall user experience.

View source


import { usePreloadedImage } from '@pluralsight/react-utils'
type ImgProps = ImgHTMLAttributes<HTMLImageElement>

usePreloadedImg(imgOptions: ImgProps)


Call usePreloadedImage at the top level of the component into which you would like to pre-load an image:

Use with Suspense

Wrap your Image components in a Suspense component to display a better UI experience for your users.

function Image(props) {
const img =
return (
<img {...img} />

export default function PreloadedImg() {
const resource = usePreloadedImg({
alt: 'random image',
src: '',

return (
<div className="App-container">
{resource && (
<Suspense fallback={<Fallback />}>
<Image alt="test image" imgData={resource.img} />
{!resource && null}


This hook accepts any property that you can place onto an img element.


An Object containing an img property that contains a read function, which returns a Promise that delivers all the image attributes when it has successfully fetched an image. Additionally, it contains a data property that contains meta-data that might be useful in a unique scenario (you will most likely never need to use this).


My images are not loading correctly

If there is a problem with the initial loading of your images, please validate that the options being passed in are valid img element attributes.

Suspense is not working when I use it with this hook

If you are combing the use of the Suspense component with this hook, ensure that you have it wrapping at the correct level. The Suspense tag should be wrapped around the component that contains the hook (its parent level).