Skip to content

Instantly share code, notes, and snippets.

@hroman-codes
Created March 30, 2021 11:33
Show Gist options
  • Save hroman-codes/7b48a3c9b41216346346bc578dd86ad7 to your computer and use it in GitHub Desktop.
Save hroman-codes/7b48a3c9b41216346346bc578dd86ad7 to your computer and use it in GitHub Desktop.
how to deal with a broken react image
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