gpt4 book ai didi

javascript - console.ignoredYellowBox 我怎么知道要使用什么前缀?

转载 作者:搜寻专家 更新时间:2023-11-01 05:09:25 24 4
gpt4 key购买 nike

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

  1. 我如何根据黄框警告消息判断如何在 React-Native 中忽略它?
  2. 如何忽略此特定警告?

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

enter image description here

所有这些React-Native documentation关于忽略特定警告的说法是:

"YellowBoxes can be disabled during development by using console.disableYellowBox = true;. Specific warnings can be ignored programmatically by setting an array of prefixes that should be ignored: console.ignoredYellowBox = ['Warning: ...'];."

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

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 的 future 版本中,console.ignoredYellowBox 将被弃用并由 YellowBox.ignoreWarnings 取代,后者将以相同的方式工作。

关于javascript - console.ignoredYellowBox 我怎么知道要使用什么前缀?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46199789/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com