Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-native lifecycle methods warning: " componentWillReceiveProps is deprecated and will be removed in the next major version"

While using the life-cycle methods in react-native, I have encountered the following warning messages in the console as well as in the emulator:

Warning: componentWillReceiveProps is deprecated and will be removed in the next major version. Use static getDerivedStateFromProps instead.

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.

The warnings are even displayed annoyingly in the emulator as follows: Warning messages in the Emulator

The problem arises whenever i dismiss the warning messages in the emulator, the application crashes, hence i have to restart the application again. What can I do about this?

Also, despite the warning messages, I have never used the method "componentWillReceiveProps". However, I have made use of the method "componentWillMount". What could be the cause of receiving warning message even related to method "componentWillReceiveProps"?

like image 805
Sarun Dahal Avatar asked Mar 13 '18 14:03

Sarun Dahal


2 Answers

I think it does not affect your application, it's just annoying.

Hide it by add below into index.js:

import { YellowBox } from 'react-native';

YellowBox.ignoreWarnings([
  'Warning: componentWillMount is deprecated',
  'Warning: componentWillReceiveProps is deprecated',
  'Module RCTImageLoader requires',
]);
like image 177
Nho Huynh Avatar answered Oct 19 '22 19:10

Nho Huynh


These deprecation notices was not due to land in React Native 0.54 but was by mistake, you can upgrade React Native to 0.54.1 and see that these messages are gone.

Read more here.

like image 30
Sam Pettersson Avatar answered Oct 19 '22 19:10

Sam Pettersson