React.js Cant replace image source when image throws a 500 error

Brady

I have a React component which basically grabs an image and outputs it. However my issue is that I cant replace the image source when the image throws a 500. My page will return the image path (/images/icons/image.png) however that image itself does not exist, so it throws a 500 on me. This is fine, the issue is it wont trigger the onerror in the image so I cant replace the broken image with a fallback image. I've tried changing state, as well as an inline onerror function. None of those will work for me. WOuld anyone has a fix for this issue. This is what my component looks like:

const VerifiedLogo = ({ src, alt, isVerified }) => (
    <div className={styles.logo}>
        <img src={src ? src : '/images/icons/tournament-logo-placeholder.png'} alt={alt} onError="this.src='/images/icons/tournament-logo-placeholder.png'" />
        <VerifiedBadge isVisible={isVerified} />
    </div>
);

export default VerifiedLogo;
Igorsvee

onError expects a function, in the constructor:

    this.state = {
      logoOk: false
    }

in the render:

<img src={this.state.logoOk ? src : altLink} onError={()=>this.setState({logoOk: false})}/>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

ObjectDisposedException when I try to use an Image source

来自分类Dev

node.js unable to serve image when it is being overwritten

来自分类Dev

当 Image.Source 为空时不渲染 Image

来自分类Dev

How to get Image.Source as string

来自分类Dev

ImageButton: Mipmap source image not stretching to fill button

来自分类Dev

未显示位图的Image.Source

来自分类Dev

<Image source = {require(“”)} />不能正确显示?

来自分类Dev

<Image source = {require(“”)} />不能正确显示?

来自分类Dev

<Image source = {require(“”)} />不能正确显示?

来自分类Dev

<Image source = {require(“”)} />不能正确显示?

来自分类Dev

动画,Image.Source和绑定

来自分类Dev

将 BitmapImage 转换为 Image.Source

来自分类Dev

WPF Image.Source 什么都不做

来自分类Dev

React-Native Image Viewer?

来自分类Dev

Show an image when using cfmail?

来自分类Dev

Run JS after image is loaded

来自分类Dev

如何在React JS中将Image-Url共享到Facebook,Twitter和Instagram

来自分类Dev

how to hide image left part of image when using overflow hidden

来自分类常见问题

React Native Image Upload File Extension错误

来自分类Dev

React Native中的Expo-Image-Picker

来自分类Dev

在React中使用<image> svg标签

来自分类Dev

React Native Image 无法解析模块

来自分类Dev

Magento: Getting 500 internal server error when creating invoices

来自分类Dev

Use base64 svg image as css content source

来自分类Dev

从资源加载图像并应用于Image.source

来自分类Dev

将Image.Source传递给XAML样式

来自分类Dev

如何获取Image.Source作为字符串

来自分类Dev

UWP:在'get;中从FilePath设置image.source;& 放;'

来自分类Dev

如何通过Xaml Behaviors设置Image Source属性?

Related 相关文章

热门标签

归档