Created
November 16, 2020 08:22
-
-
Save mkhoussid/c960ba200d6ef9142b80769a7c84e5f1 to your computer and use it in GitHub Desktop.
usePreloadImages hook (download images in the background after DOM has rendered)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This preloads images AFTER DOM has loaded | |
// See PreloadedImages.tsx for loading images before DOM is ready (https://gist.github.com/mkhoussid/d6a1a7b3d029c42bbcb45bdc929602c8) | |
import React from 'react'; | |
export default function usePreloadImages(imageUrls: string[]): void { | |
React.useEffect(() => { | |
imageUrls.forEach((imageUrl) => { | |
const image = new Image(); | |
image.src = imageUrl; | |
}); | |
}, []); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment