From 036f548ee00c4deaa1caa9c83f55c990484ce7ab Mon Sep 17 00:00:00 2001 From: Xi Chen Date: Wed, 2 Oct 2019 15:40:27 -0400 Subject: [PATCH] Optionally execute onError property function from img tag Sometimes when the component could not get the image data from a URL, instead of displaying nothing, we want some customized actions. So, if onError function is passed down to Img component, it will execute. Otherwise, it remains the current behavior. --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 0851edb3..845cd788 100644 --- a/src/index.js +++ b/src/index.js @@ -140,7 +140,7 @@ class Img extends Component { this.i .decode() .then(this.onLoad) - .catch(this.onError) + .catch(this.props.onError || this.onError) } else { this.i.onload = this.onLoad this.i.onerror = this.onError