From 528ff0d950e585e5e961ab51722a6bbc81266fa7 Mon Sep 17 00:00:00 2001 From: Fabio Lamonaca Date: Mon, 1 Aug 2022 12:21:54 +0200 Subject: [PATCH] Avoid removeEventListener Warning AppState.removeEventListenere is now deprecated. In this way you'll receive no warnings. --- index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index b546b82..06c5676 100644 --- a/index.js +++ b/index.js @@ -43,6 +43,7 @@ class CountDown extends React.Component { until: Math.max(this.props.until, 0), lastUntil: null, wentBackgroundAt: null, + appStateSubscription: null }; constructor(props) { @@ -51,12 +52,12 @@ class CountDown extends React.Component { } componentDidMount() { - AppState.addEventListener('change', this._handleAppStateChange); + this.appStateSubscription = AppState.addEventListener('change', this._handleAppStateChange); } componentWillUnmount() { clearInterval(this.timer); - AppState.removeEventListener('change', this._handleAppStateChange); + this.appStateSubscription.remove(); } componentDidUpdate(prevProps, prevState) {