当应用程序在应用模拟器中运行时,如何用React Native调试他们的React代码?
当前回答
这真的取决于我在做什么。如果我正在更改UI或调试UI,我通常会打开实时和热重新加载并进行更改,然后获得即时反馈。如果它是更技术性的东西,我打开JS调试来查看应用程序的状态。然而,因为在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问题肯定会有帮助。
希望这能帮助到一些人。
如果您正在使用模拟器使用Ctrl+M和模拟器Cmd+D 远程单击- Debug js 谷歌Chrome浏览器进入控制台
对于Android: Ctrl + M(模拟器)或摇动手机(在设备中)显示菜单。
对于iOS: Cmd + D或摇晃手机显示菜单
确保你有铬。
在显示的菜单上选择Debug JS远程选项。
Chrome将在localhost:8081/debugger-ui自动打开。您也可以使用此链接手动转到调试器。
那里显示控制台,你可以看到日志被记录。
在模拟器上按Cmd+D并选择Debug将打开浏览器调试器
你可以从brew安装React本机调试器。它比chrome中的调试器使用起来更舒服
推荐文章
- 如何删除默认的导航栏空间在SwiftUI导航视图
- 警告:API ' variable . getjavacompile()'已过时,已被' variable . getjavacompileprovider()'取代
- 安装APK时出现错误
- 碎片中的onCreateOptionsMenu
- TextView粗体通过XML文件?
- 如何使线性布局的孩子之间的空间?
- DSL元素android.dataBinding。enabled'已过时,已被'android.buildFeatures.dataBinding'取代
- ConstraintLayout:以编程方式更改约束
- PANIC: AVD系统路径损坏。检查ANDROID_SDK_ROOT值
- 如何生成字符串类型的buildConfigField
- 在react native中隐藏/显示组件
- Recyclerview不调用onCreateViewHolder
- 如何在iOS中使用Swift编程segue
- Swift -整数转换为小时/分钟/秒
- Android API 21工具栏填充