console.ignoredYellowBox如何知道要使用的前缀?

Wal*_*ari 4 javascript reactjs react-native react-native-android react-native-ios

我有一个一般性问题和两个更具体的问题.

  1. 如何从黄色框警告消息中告诉我如何在React-Native中忽略它?
  2. 如何忽略此特定警告?

在此输入图像描述 3.我如何忽略这一具体警告?

在此输入图像描述

所有关于忽略特定警告的React-Native文档都说:

"通过使用console.disableYellowBox = true;可以在开发期间禁用YellowBoxes.通过设置应忽略的前缀数组,可以以编程方式忽略特定警告:console.ignoredYellowBox = ['Warning:...'] ;."

所以React-Native提供了这段代码,但我不知道如何指定警告的名称:

console.ignoredYellowBox = ['Warning: ReactNative.createElement'];
Run Code Online (Sandbox Code Playgroud)

Nit*_*Nit 8

虽然文档中没有详细介绍,但是查看YellowBox组件代码,我们可以看到它使用简单的字符串匹配来过滤警告:

return (
  Array.isArray(console.ignoredYellowBox) &&
  console.ignoredYellowBox.some(
    ignorePrefix => warning.startsWith(String(ignorePrefix))
  )
);
Run Code Online (Sandbox Code Playgroud)

鉴于此,您可以通过执行以下操作来禁用问题中列出的错误的叠加层:

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

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

在将来版本的React Native console.ignoredYellowBox将被弃用并取代YellowBox.ignoreWarnings,它将以相同的方式工作.