Avoid using unsafe lifecycle methodsJS-0456
react
Specific legacy lifecycle methods are unsafe for use in async React applications and cause warnings in strict mode.
React 16.x introduced replacements for the following legacy methods:
componentWillMountcomponentWillReceivePropscomponentWillUpdate
These methods do the same thing as their newer counterparts (prefixed with UNSAFE_).
The only difference is that these methods will not exist in future versions of react, i.e. from React 17 onwards.
It is recommended to migrate to their aliases:
UNSAFE_componentWillMountUNSAFE_componentWillReceivePropsUNSAFE_componentWillUpdate
Bad Practice
class Card extends React.Component {
componentWillMount() {}
componentWillReceiveProps() {}
componentWillUpdate() {}
}
Recommended
class Card extends SomeOtherBaseClass {
UNSAFE_componentWillMount() {}
UNSAFE_componentWillReceiveProps() {}
UNSAFE_componentWillUpdate() {}
}