当应用程序在应用模拟器中运行时,如何用React Native调试他们的React代码?
当前回答
我没有足够的声誉来评论之前的答案,这些答案都很好。:) 以下是我在开发react-native应用程序时调试的一些方法。
Live reloading react-native makes it super easy to see your changes with the ⌘ + R keys or even just enable live reload and watchman will "refresh" the simulator with the latest changes. If you get an error, you can get a clue from the line number from that red screen. A couple of undo will get you back to working state and start again. console.log('yeah, seriously.') I find myself prefer letting the program run and logging some informations than adding a debugger break point. (tough debugger is useful when trying to work with external packages/libraries and it comes with autocompletion, so you know what other methods you can utilise.) Enable Chrome Debugging with debugger; break point in your program.
这取决于您遇到的错误类型以及您对如何调试的偏好。对于大多数未定义的不是一个对象(评估'something.something'),方法1和2对我来说已经足够好了。
然而,处理由其他开发人员编写的外部库或包将需要更多的努力来调试,因此有一个像Chrome Debugging这样的好工具
有时它来自react-native平台本身,所以谷歌一下react-native问题肯定会有帮助。
希望这能帮助到一些人。
其他回答
在React-Native中,调试要容易得多。
在IOS中使用调试
CMD + d ctrl + cmd + z(用于模拟器)
在android中调试
用触摸摇动设备(确保你的开发者选项是启用的)
如果你想了解检查网络流量和理解原生UI视图层次结构。通过其可扩展的插件API, React Native Update版本为调试移动应用程序提供了开发人员工具。
Flipper是一个调试移动应用程序的很棒的开发工具。该工具随react-native 62一起发布
我没有足够的声誉来评论之前的答案,这些答案都很好。:) 以下是我在开发react-native应用程序时调试的一些方法。
Live reloading react-native makes it super easy to see your changes with the ⌘ + R keys or even just enable live reload and watchman will "refresh" the simulator with the latest changes. If you get an error, you can get a clue from the line number from that red screen. A couple of undo will get you back to working state and start again. console.log('yeah, seriously.') I find myself prefer letting the program run and logging some informations than adding a debugger break point. (tough debugger is useful when trying to work with external packages/libraries and it comes with autocompletion, so you know what other methods you can utilise.) Enable Chrome Debugging with debugger; break point in your program.
这取决于您遇到的错误类型以及您对如何调试的偏好。对于大多数未定义的不是一个对象(评估'something.something'),方法1和2对我来说已经足够好了。
然而,处理由其他开发人员编写的外部库或包将需要更多的努力来调试,因此有一个像Chrome Debugging这样的好工具
有时它来自react-native平台本身,所以谷歌一下react-native问题肯定会有帮助。
希望这能帮助到一些人。
Mac: Cmd+M
Windows和Linux: Ctrl+M
在模拟器中使用适当的热键。它会弹出Chrome浏览器,从那里你可以使用开发人员工具。
编辑:
现在在帮助文档中有链接。
这真的取决于我在做什么。如果我正在更改UI或调试UI,我通常会打开实时和热重新加载并进行更改,然后获得即时反馈。如果它是更技术性的东西,我打开JS调试来查看应用程序的状态。然而,因为在react本机中重新加载是如此之快,如果状态太混乱,我只是控制台日志。
推荐文章
- Swift:声明一个空字典
- 如何为KnockoutJS调试模板绑定错误?
- 如何在TextView中添加一个子弹符号?
- 如何在构建目标之外生成gcc调试符号?
- PreferenceManager getDefaultSharedPreferences在Android Q中已弃用
- 在成功提交我的应用程序后,“太多符号文件”
- 在Android Studio中创建aar文件
- 首先添加一个UIView,甚至是导航栏
- 修改抽射超时时间
- 如何通过数据从第二个活动到第一个活动时按回?——安卓
- 如何在android中获得当前前景活动上下文?
- 如何在Android中获取当前日期?
- 获取Android设备名称
- 在WebView中上传文件
- 加载HTML文件到WebView