How can I delay the rendering of "My favorite image" (and the rest of the component) until the image successfully loads, which takes some time.
This is what I have attempted so far:
function ProjectCardView(props) {
const [isImageLoaded, setIsImageLoaded] = useState(false)
let imgTag = <img onLoad={() => {setIsImageLoaded(true)}} src={props.imgSrc}/>
if (!isImageLoaded) {
return <div></div>
}
return (
<div>
<h1> My favorite image </h1>
{imgTag}
</div>
)
}
This issue with this attempt is that the whole component never appears.