简体   繁体   English

反应本机不调用PropTypes警告?

[英]React native don't Call PropTypes Warnings?

can anybody suggest how to remove third party warnings? 有人可以建议如何删除第三方警告吗? https://facebook.github.io/react/warnings/dont-call-proptypes.html 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 他们从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 谢谢

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: 如果您要做的只是防止出现“ Yellow Box”调试助手,则可以使用console.ignoredYellowBox属性将不应显示的前缀列入白名单:

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. 根据评论进行编辑 :如果您想真正完全抑制console.error消息,则没有正式且合法的方法。

What you can do is monkey patch the console.error method and filter out that particular message. 可以做的是猴子修补console.error方法并过滤掉该特定消息。 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处理程序中:

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 :) 这是一个非常糟糕的主意:)

Can you show your code snippet where you are dealing with Proptypes? 您可以在处理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. 也许某些库甚至React本机代码正在触发这些React警告,因此请检查您的React本机版本是否与React正确的版本相匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM