【问题标题】:How to disable warning in React Native ?如何在 React Native 中禁用警告?
【发布时间】:2018-05-11 13:38:42
【问题描述】:

我知道警告很重要。但出于特定原因,我不希望它们出现在屏幕上。如何禁用出现在screen上的黄色警告

【问题讨论】:

  • 哪些警告?
  • 不推荐使用 invalid props typenetInfo 等警告

标签: react-native warnings


【解决方案1】:

console.disableYellowBox 已被弃用,取而代之的是 LogBox.ignoreAllLogs()

在 index.js 中刚刚设置:

import { LogBox } from "react-native"

LogBox.ignoreAllLogs(true)

import { YellowBox } from "react-native"

YellowBox.ignoreWarnings(["Warning: ..."])

编码不错!

【讨论】:

    【解决方案2】:

    建议注意这不会显示在发布版本中...但如果您想删除警告,您可以设置console.disableYellowBox = true

    文档中的更多信息:

    https://facebook.github.io/react-native/docs/debugging.html#warnings

    【讨论】:

    • 谢谢。我只是在文档中忽略了这一点。我明白了。我不希望我通过您的文档链接获得的所有警告都被忽略。
    • @Revansiddh 哈哈。没问题!
    • 这种禁用警告的方式已被弃用。现在你需要使用 LogBox.ignoreAllLogs(disable);
    【解决方案3】:

    console.disableYellowBox = true; 转 index.js .enjoy

    【讨论】:

      猜你喜欢
      • 2020-06-20
      • 1970-01-01
      • 2016-03-14
      • 1970-01-01
      • 2020-01-06
      • 2019-12-18
      • 2023-04-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多