console.ignoredYellowBox 我怎么知道要使用什么前缀?
console.ignoredYellowBox how do I know what prefix to use?
我有一个一般性问题和两个更具体的问题。
- 如何从黄框警告消息中判断如何在 React-Native 中忽略它?
- 如何忽略此特定警告?
3. 如何忽略此特定警告?
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 的未来版本中 console.ignoredYellowBox
将被弃用并被 YellowBox.ignoreWarnings
取代,后者将以相同的方式工作。
"To disable the yellow box place console.disableYellowBox = true; anywhere in your application. Typically in the root file so it will apply to both iOS and Android."
如果您想更好地控制这些消息,请查看此 link 了解更多 in-depth 信息:Disable the Yellow Box in React Native
我有一个一般性问题和两个更具体的问题。
- 如何从黄框警告消息中判断如何在 React-Native 中忽略它?
- 如何忽略此特定警告?
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 的未来版本中 console.ignoredYellowBox
将被弃用并被 YellowBox.ignoreWarnings
取代,后者将以相同的方式工作。
"To disable the yellow box place console.disableYellowBox = true; anywhere in your application. Typically in the root file so it will apply to both iOS and Android."
如果您想更好地控制这些消息,请查看此 link 了解更多 in-depth 信息:Disable the Yellow Box in React Native