I use the react native latest version of 0.54.0 and Whenever run the apps on iOS there is found warning about deprecate the lifecycle methods. and also please update the components.
Warning :
componentWillMount is deprecated and will be removed in the next major version. Use componentDidMount instead. As a temporary workaround, you can rename to UNSAFE_componentWillMount. Please update the following components: Container, Text, TouchableOpacity, Transitioner, View
I Have also change according to the waring add prefix UNSAFE_ each of the method.
UNSAFE_componentDidMount() {
}
UNSAFE_componentWillMount() {
}
UNSAFE_componentWillUpdate(nextProps, nextState) {
}
UNSAFE_componentWillReceiveProps(nextProps) {
}
Although the warning continue. Please help me.
Currently I have hide the YellowBox waring in my Apps.
import { YellowBox } from 'react-native';
render() {
YellowBox.ignoreWarnings([
'Warning: componentWillMount is deprecated',
'Warning: componentWillReceiveProps is deprecated',
]);
}
You should move all the code from the componentWillMount to the constructor or componentDidMount.
From the official docs
You should avoid using
componentWillSomething
in order to useconstructor
orcomponentDidMount
However, You have to be very carefully which one you'll use. A typical scenario is when you want to display a loading (using states) immediately after you open a screen
In this kind of case you have to use
componentDidMount
in order to set states. This is what React said aboutconstructors
Good coding!
componentDidMount
isn't deprecated and is definitely still safe to use, so there's no need to addUNSAFE_
to that method. The componentWillSomething methods are the ones that seem to be on their way out. Instead ofcomponentWillMount
, use a constructor for the stuff that doesn't produce side-effects, and usecomponentDidMount
for the stuff that does.