From 845f8e526a44f8a8c13cc87df316217f1d657afa Mon Sep 17 00:00:00 2001 From: Sam Kline Date: Tue, 1 Oct 2019 11:01:02 -0400 Subject: [PATCH] In React >=16.3, use unsafe lifecycle methods to avoid warnings, even in development --- src/components/connectAdvanced.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/components/connectAdvanced.js b/src/components/connectAdvanced.js index 33b643d43..446c90353 100644 --- a/src/components/connectAdvanced.js +++ b/src/components/connectAdvanced.js @@ -267,8 +267,8 @@ export default function connectAdvanced( if (prefixUnsafeLifecycleMethods) { // Use UNSAFE_ event name where supported - Connect.UNSAFE_componentWillReceiveProps = Connect.componentWillReceiveProps - delete Connect.componentWillReceiveProps + Connect.prototype.UNSAFE_componentWillReceiveProps = Connect.prototype.componentWillReceiveProps + delete Connect.prototype.componentWillReceiveProps } /* eslint-enable react/no-deprecated */ @@ -280,7 +280,9 @@ export default function connectAdvanced( Connect.propTypes = contextTypes if (process.env.NODE_ENV !== 'production') { - Connect.prototype.componentWillUpdate = function componentWillUpdate() { + // Use UNSAFE_ event name where supported + const eventName = prefixUnsafeLifecycleMethods ? 'UNSAFE_componentWillReceiveProps' : 'componentWillReceiveProps'; + Connect.prototype[eventName] = function componentWillUpdate() { // We are hot reloading! if (this.version !== version) { this.version = version