From ec47b3351b2b37d53240c5c842d85a3457befa78 Mon Sep 17 00:00:00 2001
From: Ethan Doh <16962469+neoswallow@users.noreply.github.com>
Date: Wed, 10 Jul 2019 16:13:11 -0400
Subject: [PATCH] Update index.js
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
With RN 0.59.9 which includes new JavaScriptCore and if children was attached with {condition && Component} format and condition is false in non other than null/undefined (false || 0 || ‘’), (false || 0 || ‘’) is returned as children. Since children is (false || 0 || ‘’), it will pick Image component but when it’s returned, props.children is not null/undefined so it will crash as Image component will see it as having children. Checking it against null will make sure that ImageBackground is chosen to prevent crash. Existing module users can prevent crash by making sure null is returned by {condition && Component || null}. Another solution would be to override children if it’s (false || 0 || ‘’) but I figure sometimes less code is better.
---
index.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/index.js b/index.js
index 9b62c56..39f1f72 100644
--- a/index.js
+++ b/index.js
@@ -148,7 +148,7 @@ export default class CachedImage extends Component {
if (this.state.source) {
- const renderImage = (props, children) => (children ?
+ const renderImage = (props, children) => (children != null ?
{children} :
);
@@ -289,4 +289,4 @@ async function _saveCacheFile(url: string, success: Function, failure: Function)
} catch (error) {
failure && failure(error);
}
-}
\ No newline at end of file
+}