当应用程序在应用模拟器中运行时,如何用React Native调试他们的React代码?


当前回答

这是使用react本机调试器应用程序的另一种方式。

你可以使用下面的链接下载应用程序,这是一个非常好的应用程序,用于管理redux商店的源代码。

react-native-debugger

现在你可以直接使用下面的链接来帮助你。

chrome开发工具

其他回答

在模拟器上按Cmd+D并选择Debug将打开浏览器调试器

还有一个非常好的调试器Reactotron。 https://github.com/infinitered/reactotron

您不必在调试模式下查看一些数据值,而且有很多选项。

去看看真的很有用。;)

我没有足够的声誉来评论之前的答案,这些答案都很好。:) 以下是我在开发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原生应用程序

要调试react应用程序的javascript代码,请执行以下操作:

在iOS模拟器中运行应用程序。 按Command + D,打开一个网页http://localhost:8081/debugger-ui。(Chrome只现在)或使用摇手势 为更好的调试体验启用暂停捕获异常。 按命令+选项+ I打开Chrome开发工具,或通过视图->开发人员->开发人员工具打开。 现在您应该能够像往常一样进行调试了。

可选

为谷歌Chrome安装React开发人员工具扩展。当开发人员工具打开时,如果你选择React选项卡,这将允许你在视图层次结构中导航。

生活重新加载

要激活Live Reload,请执行以下操作:

在iOS模拟器中运行应用程序。 按Control + Command + Z键。 您现在将看到启用/禁用Live Reload,重新加载和启用/禁用调试选项。

奇怪的是,⌘+ D对我不起作用。在iOS模拟器中按ctrl + cmd⌘+ Z确实为我打开了调试浏览器窗口。

这是弹出的屏幕:

详情请点击这里。