Created
March 30, 2021 11:33
-
-
Save hroman-codes/7b48a3c9b41216346346bc578dd86ad7 to your computer and use it in GitHub Desktop.
how to deal with a broken react image
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
const MyCard = (props) => { | |
const { item } = props; | |
const defaultImgUrl = 'path to image' | |
const handleError = (event) => { | |
event.target.src = defaultImgUrl; | |
}; | |
return ( | |
<div> | |
<h1>item.name</h1> | |
<img src={item.img} onError={handleError} /> | |
<p>{item.description}</p> | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment