From 5da836f651766f4f1e15be92e355d8eb20d0de58 Mon Sep 17 00:00:00 2001 From: Mateo Silguero Date: Tue, 24 Sep 2019 09:26:16 -0300 Subject: [PATCH] componentWillReceiveProps will be deprecated --- src/OfflineImage.js | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/OfflineImage.js b/src/OfflineImage.js index 727e112..363a9f3 100644 --- a/src/OfflineImage.js +++ b/src/OfflineImage.js @@ -34,20 +34,13 @@ class OfflineImage extends React.Component { } }; - // FIXME : Get rid of return true and improve render component logic - shouldComponentUpdate(nextProps, nextState) { - return true - // if (!nextState.path) return true - // return this.state.path !== nextState.path || this.props.opacity !== nextProps.opacity; - } - - componentWillReceiveProps(nextProps) { - const nextSource = nextProps.source; - const reloadImage = nextProps.reloadImage; + componentDidMount(prevProps) { + const nextSource = prevProps.source; + const reloadImage = prevProps.reloadImage; - const source = this.props.source; - if (nextSource.uri !== source.uri){ - const offlinePath = offlineImageStore.getImageOfflinePath(nextSource.uri); + const { source } = this.props; + if (prevProps.uri !== source.uri){ + const offlinePath = offlineImageStore.getImageOfflinePath(source.uri); this.setState({ path: offlinePath }); offlineImageStore.subscribe(source, this.handler, reloadImage); } @@ -61,7 +54,7 @@ class OfflineImage extends React.Component { } } - componentWillMount() { + componentDidMount() { /** * Always download and update image in offline store if 'reloadImage' === 'always', however * Case 1: Show offline image if already exist