我怎样才能抑制“标签<some-tag>在此浏览器中无法识别"反应中的警告? [英] How can I suppress "The tag <some-tag> is unrecognized in this browser" warning in React?

查看:21
本文介绍了我怎样才能抑制“标签<some-tag>在此浏览器中无法识别"反应中的警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 React 中使用带有自定义标签名称的元素,并且遇到了这些错误.这个主题有一个 GitHub 问题(https://github.com/hyperfuse/react-anime/issues/33),其中有人说:

I'm using elements with custom tag names in React and getting a wall of these errors. There's a GitHub issue on the subject (https://github.com/hyperfuse/react-anime/issues/33) in which someone states:

这是 React 16 中的新警告消息.与anime/react-anime 无关,可以安全地忽略此警告.

This is a new warning message in React 16. Has nothing to do with anime/react-anime and this warning can safely be ignored.

很高兴可以安全地忽略它,但是当我的代码用无用的错误消息填充控制台时,它仍然不会通过审查.

It's nice that it can be safely ignored, but it's still not going to pass scrutiny when my code is filling the console with useless error messages.

如何抑制这些警告?

推荐答案

更新:

请参阅@triple 的答案以及正确的解决方案:https://stackoverflow.com/a/55537927/1483006

see the answer from @triple with the correct solution: https://stackoverflow.com/a/55537927/1483006

原始:

我并不是说这是您应该真正做的正确的事情,但是您可以挂钩 console.error 并通过将其放在 react-anime 之前的某个位置来过滤此消息已加载:

I'm not saying this a correct thing you should really do, but you could hook console.error and filter this message by putting this somewhere before react-anime is loaded:

const realError = console.error;
console.error = (...x) => {
  // debugger;
  if (x[0] === 'Warning: The tag <g> is unrecognized in this browser. If you meant to render a React component, start its name with an uppercase letter.') {
    return;
  }
  realError(...x);
};

它似乎适用于至少在您链接的 GitHub 问题中发布的示例.:3

It seemed to work on the sample that was posted in the GitHub issue you linked at least. :3

这篇关于我怎样才能抑制“标签&lt;some-tag&gt;在此浏览器中无法识别"反应中的警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆