当应用程序在应用模拟器中运行时,如何用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问题肯定会有帮助。

希望这能帮助到一些人。

其他回答

其实很简单。只需按cmd D(如果在mac上),模拟器将创建一个弹出菜单。从那里只需点击“调试JS远程”或类似的东西。注意,在执行与某些包相关的代码时运行调试器会给人们带来问题。我有一个问题与反应本机映射和调试器。但这是固定的。不过,在大多数情况下,你应该没问题。

要调试你的react原生应用程序,只需到以下地址:

localhost: 8081 / debugger-ui 在你的默认浏览器(chrome)和打开开发者工具来调试你的react原生应用程序

使用Flipper或retotron。每一种都有自己的好处,没有一种要求您启用调试模式,所以您的环境不会变慢!

如果你想在Windows上使用android设备调试,只需打开命令提示符,然后输入(确保你的adb工作正常)

adb shell input keyevent 82

它将提示一个类似于图像的屏幕

然后选择

debug JS Remotely

它会自动打开一个新窗口。然后打开检查元件或按F12进入控制台。

我没有足够的声誉来评论之前的答案,这些答案都很好。:) 以下是我在开发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问题肯定会有帮助。

希望这能帮助到一些人。