From 5c2b4afa41cb73815b830cee9668747ff05e2d3e Mon Sep 17 00:00:00 2001 From: Dylan Vann Date: Sat, 20 Apr 2019 21:53:00 -0400 Subject: [PATCH] perf: Use React.memo for FastImage. (#449) --- src/index.js | 92 +++++++++++++++++++++++++++------------------------- 1 file changed, 47 insertions(+), 45 deletions(-) diff --git a/src/index.js b/src/index.js index ea2187e..5309fe7 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,4 @@ -import React, { forwardRef } from 'react' +import React, { forwardRef, memo } from 'react' import PropTypes from 'prop-types' import { View, @@ -11,59 +11,61 @@ import { const FastImageViewNativeModule = NativeModules.FastImageView -const FastImage = forwardRef( - ( - { - source, - onLoadStart, - onProgress, - onLoad, - onError, - onLoadEnd, - style, - children, - fallback, - ...props - }, - ref, - ) => { - const resolvedSource = Image.resolveAssetSource(source) - - if (fallback) { - return ( - - - {children} - - ) - } +function FastImageBase({ + source, + onLoadStart, + onProgress, + onLoad, + onError, + onLoadEnd, + style, + children, + fallback, + forwardedRef, + ...props +}) { + const resolvedSource = Image.resolveAssetSource(source) + if (fallback) { return ( - - + {children} ) - }, -) + } + + return ( + + + {children} + + ) +} + +const FastImageMemo = memo(FastImageBase) + +const FastImage = forwardRef((props, ref) => ( + +)) FastImage.displayName = 'FastImage'