From 3581fac6841011443bd2a16240d0de7d85d94b81 Mon Sep 17 00:00:00 2001 From: meriadec Date: Tue, 4 Sep 2018 18:11:03 +0200 Subject: [PATCH] Prevent calling setState if unmounted on CurrentAddress --- src/components/CurrentAddress/index.js | 39 ++++++++++++++------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/components/CurrentAddress/index.js b/src/components/CurrentAddress/index.js index 488bf105..bf979fbc 100644 --- a/src/components/CurrentAddress/index.js +++ b/src/components/CurrentAddress/index.js @@ -143,7 +143,26 @@ class CurrentAddress extends PureComponent { copyFeedback: false, } - _isUnmounted = false + componentWillUnmount() { + if (this._timeout) clearTimeout(this._timeout) + } + + renderCopy = copy => { + const { t } = this.props + return ( + } + label={t('app:common.copyAddress')} + onClick={() => { + this.setState({ copyFeedback: true }) + this._timeout = setTimeout(() => this.setState({ copyFeedback: false }), 1e3) + copy() + }} + /> + ) + } + + _timeout: ?TimeoutID = null render() { const { @@ -214,23 +233,7 @@ class CurrentAddress extends PureComponent { onClick={onVerify} /> ) : null} - ( - } - label={t('app:common.copyAddress')} - onClick={() => { - this.setState({ copyFeedback: true }) - setTimeout(() => { - if (this._isUnmounted) return - this.setState({ copyFeedback: false }) - }, 1e3) - copy() - }} - /> - )} - /> + )