React Native life cycle methods is in updating process and since the updation is began we all have seen 2 Errors on our newly created react native applications while using componentDidMount(), componentWillReceiveProps() and componentWillMount() inbuilt methods of react’s. This error is very irritating and makes your application look awkward. So after finding a lot on react’s official page and reading its all methods we have finally find the solution to hide this error using YellowBox component of react native. So in this tutorial we would going to Solve Warning componentwillmount is Deprecated and will be Removed in the Next Major Version in react native android iOS application screen.
Screenshot of componentWillMount() error:
Warning: componentWillMount is deprecated and will be removed in the next major version. Use componentDidMount instead. As a temporary workarount, you can rename to UNSAFE_componentWillMount. Please update the following components : ActivityIndicator, View. Learn more about this warning here: https://fb.me/react-async-component-lifecycle-hooks .
Screenshot of componentWillReceiveProps() error :
Warning: componentWillReceiveProps is deprecated and will be removed in the next major version. Use static getDerivedStateFromProps instead. Please update the following components : ActivityIndicator, View. Learn more about this warning here: https://fb.me/react-async-component-lifecycle-hooks .
Solution of Warning componentwillmount is Deprecated and will be Removed in the Next Major Version :
1. This warning message is a temporary message and will be removed soon with the new react native version but its very irritating so we can easily remove this error by using YellowBox component in our react native project. This component will handle all the warning messages shows inside the yellow box. So import YellowBox component in your project.
1
2
3
|
import React, { Component } from ‘react’;
import { YellowBox } from ‘react-native’;
|
2. Call its inbuilt warning ignore method inside constructor() of your default class.
1
2
3
4
5
6
7
8
9
10
|
constructor(props) {
super(props);
YellowBox.ignoreWarnings([
‘Warning: componentWillMount is deprecated’,
‘Warning: componentWillReceiveProps is deprecated’,
]);
}
|
After using this ignoreWarnings() method all the 6 warning message will successfully removed(Hide) from your react native android iOS mobile application screen .