Created
September 14, 2021 18:50
-
-
Save rishi23root/32a88bf23b134c9d768c2c16c7fe1b1a to your computer and use it in GitHub Desktop.
Image preLoader for react 'to show loading circle till the image loads'
This file contains 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
import React, { useState, Suspense } from 'react'; | |
import CircularProgress from '@material-ui/core/CircularProgress'; | |
export default function Image({ src, alt }) { | |
const [isloaded, setIsloaded] = useState(false); | |
return ( | |
<> | |
<img | |
className={isloaded ? "ImageItself " : "displayNone"} | |
src={src} | |
alt={alt || "Poster for the movie"} | |
onLoad={() => { | |
console.log(132) | |
setIsloaded(true) | |
}} | |
/> | |
{!isloaded && <CircularProgress color="secondary" />} | |
</> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment