console.ignoredYellowBox如何知道使用哪个前缀?

问题描述:

我有一个一般问题和两个更具体的问题。console.ignoredYellowBox如何知道使用哪个前缀?

  1. 如何从黄箱警告消息中看出如何在React-Native中忽略它?
  2. 如何忽略此特定警告?

enter image description here 3.如何忽略此特定警告?

enter image description here

所有这一切React-Native documentation说,大约忽略特定的警告是:

“YellowBoxes在开发过程中使用 console.disableYellowBox = TRUE ;.具体警告被禁用,可以通过编程忽略 设置应该被忽略的前缀数组:012.应该是 :console.ignoredYellowBox = ['Warning:...'] ;.“

等反应过来,本地提供这一段代码,但我不知道如何指定警告的名字:

console.ignoredYellowBox = ['Warning: ReactNative.createElement']; 

虽然不涉及详细的文档,看着the YellowBox component code,我们可以看到它使用一个简单的字符串匹配过滤警告:

return (
    Array.isArray(console.ignoredYellowBox) && 
    console.ignoredYellowBox.some(
    ignorePrefix => warning.startsWith(String(ignorePrefix)) 
) 
); 

鉴于此,你可以简单地通过执行以下禁用的问题列出的错误覆盖:

console.ignoredYellowBox = [ 
    'NetInfo\'s "change" event', // Safe to ignore because reasons 
    'Using <Image> with children' // TODO: Will be fixed in release foo 
]; 

您可以根据需要使匹配更具体或更模糊,因为它是简单的字符串匹配。
请注意,错误仍将记录到控制台,上述配置只是为给定的错误禁用大的黄色覆盖。

React Native console.ignoredYellowBox的未来版本将被弃用,并由YellowBox.ignoreWarnings取代,这些版本将以相同的方式工作。

“要禁用黄色方块位置console.disableYellowBox = true;应用程序中的任何位置,通常位于根文件中,因此它适用于iOS和Android。

如果您想对这些消息进行更多控制,请查看以下链接以获取更多深入信息:Disable the Yellow Box in React Native