Skip to content

Instantly share code, notes, and snippets.

@mkhoussid
Created November 16, 2020 08:22
Show Gist options
  • Save mkhoussid/d6a1a7b3d029c42bbcb45bdc929602c8 to your computer and use it in GitHub Desktop.
Save mkhoussid/d6a1a7b3d029c42bbcb45bdc929602c8 to your computer and use it in GitHub Desktop.
PreloadImages component (download images before DOM has loaded)
// This preloads images BEFORE DOM has loaded
// See usePreloadImages.ts for loading images after DOM has loaded (https://gist.github.com/mkhoussid/c960ba200d6ef9142b80769a7c84e5f1)
import React from 'react';
type TPreloadImages = {
imageUrls: string[];
};
export default React.memo(({ imageUrls }: TPreloadImages) => {
return (
<div style={{ display: 'none' }}>
{imageUrls.map((imageUrl) => (
<img src={imageUrl} />
))}
</div>
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment