debugging - React 导航:如何调试
问题描述
我有一个应用程序,我在其中配置了多条路线,并且一切正常,直到我配置的最新路线不起作用(显示错误的屏幕)。
我的问题是如何进行调试?没有打印错误日志,我找不到如何获取更多关于正在发生的事情的日志。我也不知道在哪里停止调试器以获取一些有用的信息。
解决方案
在哪里记录
您可以使用这 2 个侦听器来记录某些内容:
willFocus
- 屏幕将聚焦
componentDidMount() {
this.props.navigation.addListener("willFocus", () => console.log(""));
}
willBlur
- 屏幕将不聚焦
componentDidMount() {
this.props.navigation.addListener("willBlur", () => console.log(""));
}
另外,请查看文档以查看更多听众。
记录什么
获取navigator
事件发生时的状态:
let state = this.props.navigation.dangerouslyGetState();
从这里,您可以看到可用的路线state.routeNames
。您还可以goBack
使用state.routes
.
推荐阅读
- python - 无法获得 gunicorn 访问日志响应时间的毫秒级读数
- python - Groupby 日期,但填充来自不同行的空值并对数字求和
- logging - Rule Execution Server 中的规则集级别日志记录
- docker - 将主机添加到 docker windows 容器中的 etc/hosts
- javascript - 尝试将道具分配给状态变量的反应不起作用
- python - 在for循环中比较python中JSON对象的值
- c# - 生成还原了 NuGet 包。再次构建项目以在构建中包含这些包
- c# - 如何直接在 WCF 响应对象中返回多个字段,而不是包装在另一个对象中?
- flutter-layout - 如何防止 setState((){}); 颤抖?
- kubernetes - 主机名未在命名空间中注册