React Native mobile development practices-2-how to debug the React Native project-2-react
In actual development, there is also an important factor that affects development efficiency: debugging.
The use of Enable Live Debugger is introduced in Section 1.4.3. This section describes another important debugging option: Debug JSRemotely.
(1) Shake the device or use the keyboard shortcut on the simulator (iOS simulator shortcut: command + d, Android simulator shortcut: command + m) to open the debugging option, as shown in Figure 2.15.
Figure 2.15 React Native debugging options
(2) Click the Debug JS Remotely option. In this case, React Native automatically opens the Chrome browser as a debugging tool.
(3) perform operations in the order shown in 2.16, so that the debugging status of the React Native application is entered.
Figure 2.16 use Chrome to debug the ReactNative Application
(4) In the debugging status, click the number of lines in row 12th of the index. ios. js file to add a breakpoint, as shown in Figure 2.17.
[Question] What is a breakpoint in software development?
[Answer] resumable point is one of the functions of the debugger. When a Breakpoint is set during debugging, the program can be stopped when it runs the program. In this way, when the program reaches the Breakpoint, its variables, latches, I/O, and other related variables help you gain an in-depth understanding of program operation mechanisms and discover and eliminate the root cause of program errors.
Figure 2.17 Add a breakpoint during React Native debugging
(5) Finally, reload the running application (the iOS simulator shortcut key is command + r, and the Android simulator shortcut key is r + r ). At this point, the application stops running to the 12th line that just added the breakpoint, as shown in Figure 2.18.
Figure 2.18 paused at the breakpoint during React Native debugging
At this point, you can view the information in the debugging area on the right: the thread status (Threads), variable value, Call Stack, and other information of the current application execution. In addition, you can use commands at the top of the debugging area to perform single-step execution, skip execution, and continue execution, as shown in Figure 2.19.
Figure 2.19 Debugging commands for React Native debugging
Debugging skills and experience need to be accumulated continuously during the development process. After mastering these basic usage, you can continue to practice and accumulate development experience through the following examples, improve debugging capability and development efficiency.
Learn With Me, React Native mobile development practices