当应用程序在应用模拟器中运行时,如何用React Native调试他们的React代码?
当前回答
对于Android: Ctrl + M(模拟器)或摇动手机(在设备中)显示菜单。
对于iOS: Cmd + D或摇晃手机显示菜单
确保你有铬。
在显示的菜单上选择Debug JS远程选项。
Chrome将在localhost:8081/debugger-ui自动打开。您也可以使用此链接手动转到调试器。
那里显示控制台,你可以看到日志被记录。
其他回答
除了其他答案。可以使用调试器语句调试react-native
例子:
debugger; //breaks execution
你的chrome开发工具必须打开这工作
试试这个程序:https://github.com/jhen0409/react-native-debugger
适用于:windows, osx和linux。
它支持:react native和redux
你还可以检查虚拟组件树,修改应用中反映的样式。
你可以从brew安装React本机调试器。它比chrome中的调试器使用起来更舒服
在模拟器- react-native Run -ios中运行你的应用程序 按ctrl + d,然后点击Debug JS remote
网页应该在http://localhost:8081/debugger-ui打开,如果没有输入URL,在Chrome中进入这个链接 右键点击页面,点击检查,它应该打开chrome开发工具
转到顶部菜单中的源代码,在右侧的文件资源管理器中找到你的js类文件 您可以将断点放到视图中,并在其中调试代码,如图所示。
我没有足够的声誉来评论之前的答案,这些答案都很好。:) 以下是我在开发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问题肯定会有帮助。
希望这能帮助到一些人。
推荐文章
- BottomSheetDialogFragment的圆角
- 在应用程序启动时出现“无法获得BatchedBridge,请确保您的bundle被正确打包”的错误
- 我如何改变默认对话框按钮的文本颜色在安卓5
- 更改单选按钮的圆圈颜色
- 如何在android中复制一个文件?
- adb找不到我的设备/手机(MacOS X)
- 如何使用Xcode创建。ipa文件?
- 动态改变UILabel的字体大小
- 如何在新的材质主题中改变背面箭头的颜色?
- androidviewpager与底部点
- 相同的导航抽屉在不同的活动
- 如何从视图中获得托管活动?
- 单一的TextView与多种颜色的文本
- 如何在非活动类(LocationManager)中使用getSystemService ?
- 在清单中注册应用程序类?