React native不要调用PropTypes Warnings

React native don't Call PropTypes Warnings?

本文关键字:PropTypes Warnings 调用 native React      更新时间:2023-09-26

谁能建议如何删除第三方警告?https://facebook.github.io/react/warnings/dont-call-proptypes.html

我不知道如何实现以及在哪里放置官方文档中提到的代码。它们从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);
};
}

请写一步一步解决第三方警告。

谢谢

您可以显示您的代码片段在哪里处理Proptypes?也许一些库或甚至react native代码触发了这些react警告,所以检查你的react native版本是否与react正确的版本匹配。

如果你想阻止"Yellow Box"调试助手出现,你可以使用console.ignoredYellowBox属性将不应该显示的前缀列入白名单:

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

基于注释编辑:如果您想实际抑制控制台。错误信息,没有官方和合法的方法来做到这一点。

可以做的是猴子补丁console.error方法并过滤掉特定的消息。修补程序需要在您的应用程序代码被评估之后,但在挂载有问题的组件之前进行。

一个好的地方将是在根组件的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);
    }
  };
}

但是请,请不要这样做。这真是个坏主意