最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - React Native Image how to use onError - Stack Overflow

programmeradmin5浏览0评论

Hi I'm currently trying to load several network images and they often fail to load on android. I'm trying to use onError to diagnose why but can't seem to get it to work.

I've tried using it as

onError={(e) => console.log(e}

and

onError(error){
  console.log(error)
}

onError={ this.onError.bind(this) }

but both of these result in this object

Proxy [[Handler]]: Object [[Target]]: SyntheticEvent [[IsRevoked]]: false

which, as best as I can tell, is the error event and doesn't contain anything useful.

My question is how do I use onError to diagnose why my network images are failing? but if you have any ideas about why I'll gladly take those too.

Hi I'm currently trying to load several network images and they often fail to load on android. I'm trying to use onError to diagnose why but can't seem to get it to work.

I've tried using it as

onError={(e) => console.log(e}

and

onError(error){
  console.log(error)
}

onError={ this.onError.bind(this) }

but both of these result in this object

Proxy [[Handler]]: Object [[Target]]: SyntheticEvent [[IsRevoked]]: false

which, as best as I can tell, is the error event and doesn't contain anything useful.

My question is how do I use onError to diagnose why my network images are failing? but if you have any ideas about why I'll gladly take those too.

Share Improve this question asked Mar 6, 2018 at 17:28 tjkindtjkind 1711 gold badge1 silver badge7 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 15

This is an SyntheticEvent, as specified in the Image doc here, you can try following code

onError=({ nativeEvent: {error} }) => console.log(error)

Hope this will help.

try this

 <Image
                    onError={(error) => {

                      const getCircularReplacer = () => {
                        const seen = new WeakSet();
                        return (key, value) => {
                          if (typeof value === "object" && value !== null) {
                            if (seen.has(value)) {
                              return;
                            }
                            seen.add(value);
                          }
                          return value;
                        };
                      };
                      console.log("this Images Error ")
                      console.log(JSON.stringify(error, getCircularReplacer()))

                    } 
                    }
                    />
发布评论

评论列表(0)

  1. 暂无评论