0

can anybody suggest how to remove third party warnings? https://facebook.github.io/react/warnings/dont-call-proptypes.html

i don't know how to implement and where to put code that official documentation mentioned. They take code from react-bootstrap

export default function deprecated(propType, explanation) {
   return function validate(props, propName, componentName) {
if (props[propName] != null) {
      const message = `"${propName}" property of 
         "${componentName}" has       been deprecated.\n${explanation}`;
  if (!warned[message]) {
    warning(false, message);
    warned[message] = true;
  }
}

return propType(props, propName, componentName);
};
}

Please write step by step to resolve third party warnings.

Thanks

Waleed Arshad
  • 1,081
  • 3
  • 12
  • 24

2 Answers2

0

If all you are trying to do is to prevent the "Yellow Box" debugging helper from appearing, you can use the console.ignoredYellowBox property to whitelist prefixes that should not be shown:

const existingIgnoreList = console.ignoredYellowBox;
const prefixesToIgnore = [
  'Warning: "foo" property of "Bar"'
];

console.ignoredYellowBox = existingIgnoreList
  ? existingIgnoreList.concat(prefixesToIgnore)
  : prefixesToIgnore;

Edit based on comments: If you want to actually suppress the console.error message entirely, there is no official and legitimate way to do this.

What you can do is monkey patch the console.error method and filter out that particular message. The patching needs to happen after your application code has been evaluated, but before the offending component is mounted.

A good place would be in your root component's componentWillMount handler:

componentWillMount() {
  console.__error = console.error;
  console.error = function overrideConsoleError(...args) {
    if (!typeof args[0] === 'string' || !args[0].startsWith('Warning: "foo" property of "Bar"')) {
      console.__error(...args);
    }
  };
}

But please, please don't actually do this. This is a really bad idea :)

jevakallio
  • 35,324
  • 3
  • 105
  • 112
  • yes there is a yellow box but official docs suggest something else. i am more willing to follow the recommendations that they mention in their official docs. anything you can suggest from the above code. The solution you provided already on the stackoverflow http://stackoverflow.com/questions/38907803/how-to-suppress-warning-due-to-a-third-party-proptypes-library-in-react-native/38907884?noredirect=1#comment65901347_38907884 – Waleed Arshad Sep 02 '16 at 06:15
  • After implementing this solution, i am still having warning in red color in debugging console. – Waleed Arshad Sep 02 '16 at 06:16
  • 1
    The problem is that the offending code isn't in your own codebase, it's in a third party module. The docs in your question are something the library author should do. In order for **you** to fix it you need to fork that library, patch the original cause of the problem, submit a pull request, wait for a new release etc. While you do that, if you need to remove the error, I've added a fun and creative way to get around the problem :) – jevakallio Sep 02 '16 at 14:18
0

Can you show your code snippet where you are dealing with Proptypes? Maybe some library or even react native code is triggering these React warnings so check if your react native version matches the react right one.

RN_starter
  • 11
  • 2