Home > Mobile >  How to disable ComponentWill... warnings when they are coming from dependencies
How to disable ComponentWill... warnings when they are coming from dependencies

Time:09-24

Issue

I am getting constant yellow warnings from React Native about component lifecycle, such as ComponentWillMount being deprecated These warnings come from dependencies, and not from my components.

What I do not need

I can't fix this by disabling the yellow box altogether, nor can I modify React Native's code directly, meaning a solution like this in RN's renderApplication.js isn't valid:

const backup = console.warn;

console.warn = function filterWarnings(warning) {
  const supressedWarnings = [
    'Warning: componentWillMount has been renamed, and is not recommended for use.',
    'Warning: componentWillReceiveProps has been renamed, and is not recommended for use.',
    'Warning: componentWillUpdate has been renamed, and is not recommended for use.',
  ];

  if (
    warning.length &&
    !supressedWarnings.some((entry) => warning.includes(entry))
  ) {
    backup.apply(console, arguments);
  }
};

I also cannot modify the code from the dependencies.

Question

Can I disable these warnings from a place such as the application's root file, and if so how can I do it?

CodePudding user response:

I'm not really sure what you are doing with filterWarnigns but you can disable warning through the LoxBox.

E.g.:

import { LogBox } from 'react-native';

// Ignore log notification by message:
LogBox.ignoreLogs([
    'Warning: componentWillMount has been renamed, and is not recommended for use.',
    'Warning: componentWillReceiveProps has been renamed, and is not recommended for use.',
    'Warning: componentWillUpdate has been renamed, and is not recommended for use.',
]);

For react-native versions below 0.63 use YellowBox:

import { YellowBox } from 'react-native';

YellowBox.ignoreWarnings([
    'Warning: componentWillMount has been renamed, and is not recommended for use.',
    'Warning: componentWillReceiveProps has been renamed, and is not recommended for use.',
    'Warning: componentWillUpdate has been renamed, and is not recommended for use.',
]);
  • Related