Skip to content

Commit 2978315

Browse files
samklinetimdorr
authored andcommitted
In React >=16.3, use unsafe lifecycle methods to avoid warnings, even in development (#1410)
1 parent 4144715 commit 2978315

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/components/connectAdvanced.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@ export default function connectAdvanced(
267267

268268
if (prefixUnsafeLifecycleMethods) {
269269
// Use UNSAFE_ event name where supported
270-
Connect.UNSAFE_componentWillReceiveProps = Connect.componentWillReceiveProps
271-
delete Connect.componentWillReceiveProps
270+
Connect.prototype.UNSAFE_componentWillReceiveProps = Connect.prototype.componentWillReceiveProps
271+
delete Connect.prototype.componentWillReceiveProps
272272
}
273273

274274
/* eslint-enable react/no-deprecated */
@@ -280,7 +280,9 @@ export default function connectAdvanced(
280280
Connect.propTypes = contextTypes
281281

282282
if (process.env.NODE_ENV !== 'production') {
283-
Connect.prototype.componentWillUpdate = function componentWillUpdate() {
283+
// Use UNSAFE_ event name where supported
284+
const eventName = prefixUnsafeLifecycleMethods ? 'UNSAFE_componentWillUpdate' : 'componentWillUpdate';
285+
Connect.prototype[eventName] = function componentWillUpdate() {
284286
// We are hot reloading!
285287
if (this.version !== version) {
286288
this.version = version

0 commit comments

Comments
 (0)