View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All

React Native Debugging: Techniques, Tools, How to Use it?

By Pavan Vadapalli

Updated on Oct 25, 2024 | 5 min read | 23.4k views

Share:

Debugging in the React Native universe may be done in various ways and with various tools, as React Native is built up of distinct environments (iOS and Android), which means there are a variety of problems to solve with tools to use. React Native Debugging entails a detailed examination of the code and aids in the early detection of errors. 

Fixing these problems or defects during the React Native app development process rather than during the production stages will save money for any React Native app development company. Thanks to the vast number of contributors to the React Native ecosystem, many debugging tools are available. 

What is React Native Debugging?

React native debugging is essential for developing apps. It is a process of identifying, detecting and fixing bugs or issues. A thorough understanding of debugging techniques like Chrome developer tools or React Native Debugger enables more rapid and efficient software development. 

We will go through a couple of debugging approaches in React Native here. We will be developing, running, and debugging our apps with expo-cli, one of the simplest and fastest ways to construct a React Native app. 

React Native Debugging Techniques

The following are some common react native debugging techniques: 

  • Logging 
  • Debugging in chrome browser 
  • Debugging in visual studio code 

1. Logging 

It is a simple and quick way to debug your software while still in development. It is one of the most straightforward methods for learning how an application works. To log, we just utilize the console.log() instructions to record the appropriate data or indicators. However, we must never forget to remove these console.log() statements before submitting our product to the development phase, as they will only add overhead. 

2. Debugging in Chrome Browser 

We may activate Remote Debugging in our application, which will allow us to debug React Native code in a Chrome browser tab, like how we debug web applications with Chrome developer tools. 

3. Debugging in Visual Studio Code 

We can utilize React Native Tools, a VS Code addon used for debugging React Native projects. Simply create a new file named Launch.json after installing the extension, which will be used to debug the configuration file construction. Finally, we must enable Debug JS Remotely as well as Live Reload. We can now begin debugging with VS Code. 

Professional online programmes like the Full Stack Software Development Bootcamp from upGrad offer extensive knowledge about tools like the React debugger to develop error-free programs and applications.

Features of React Native Debugger 

Here are the features of React Native Debugger

1. UI Inspector

You must be aware of element inspector if you are a web developer. The UI Inspector in React Native Debugger works similarly: one can see all the tags used in your app and inspect their styling. You can use the inspector to test your UI and adjust the styling. 

This is, by far, the most efficient approach to viewing and debugging UI hierarchy in React Native projects. 

2. Debug Redux

You will need a state management library whether you are working on a React or React Native app. Redux is one of the most popular state management libraries on the market. 

However, especially in React Native, using Redux might be a nuisance if you cannot debug your state. You may use React Native Debugger to debug your Redux-based project easily. You may even debug the current condition in real-time. 

Until we specifically If we do not use redux devtools in our project, it will not work properly. As seen in the code snippet below, first must enable redux in our app by inserting certain config lines to our App.js file either to our redux main function, to use redux devtools in the react-native-debugger: 

const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose; 

const store = createStore(reducers, /* preloadedState, */ composeEnhancers(middlewares)); 

If we now reload our RN Debugger tool and perform some activities, we will see the following in the debugger console: 

As you will see, the React Native Debugger exposes the entire Redux state, so users do not need to use breakpoints or console logs to figure out how data flow in the redux system. One incredible feature is the ability to go back in time directly from the debugger to reverse and re-run Redux activities. Another notable feature is the ability to see the exact difference between two state transitions, which is especially useful for projects with many Redux states. 

3. Network Inspector

In general, we may not know what is happening behind the scenes while designing an app that needs to connect to a server. When submitting a request to the server, for example, it may be difficult to track down an issue. Developers typically debug this by printing or alerting error messages; however, this is time-consuming (even though most people do it), as it takes many iterations to comprehend the condition fully. 

We can easily monitor every inbound and outbound traffic request between the app and the server using the React Native Debugger. 

4. AsyncStorage Management

You can easily print or log your AsyncStorage on the console by running the following command: 

console.log(showAsyncStorageContentInDev()) 

This will print or report the AsyncStorage data in the terminal on React Native Debugger. 

5. Breakpoints

The React Native Debugger also allows us to pause the execution job anytime. This will allow developers to inspect data states or understand app activity anytime during the app's lifecycle. 

Check Out upGrad’s Software Development Courses to upskill yourself.

How to Debug React Native App? [Step-by-Step]

Step 1: Run your application in the iOS simulator. 

Step 2: Press Command + D and a webpage should open at http://localhost:8081/debugger-ui. (Chrome only for now) or use the Shake Gesture 

Step 3: Enable Pause On Caught Exceptions for a better debugging experience. 

Step 4: Press Command + Option + I to open the Chrome Developer tools or open it via View -> Developer -> Developer Tools. 

Step 5: You should now be able to debug as you normally would. 

Enabling Keyboard Shortcuts 

In the iOS Simulator, React Native supports a few keyboard shortcuts. They are outlined below. To make them work, 

==> Go to the Hardware menu

==> Pick Keyboard

==> And check "Connect Hardware Keyboard." 

Accessing In-App Developer Menu

Shake your device or pick "Shake Gesture" from the Hardware menu in the iOS Simulator to get to the developer menu. When your app runs in the iOS Simulator, or M when executing in an Android emulator on Mac OS, or Ctrl+M on Windows and Linux, developers can use the D keyboard shortcut. To open the dev menu on an Android device, use the command adb shell input keyevent 82. (82 being the Menu key code). 

Coverage of AWS, Microsoft Azure and GCP services

Certification8 Months
View Program

Job-Linked Program

Bootcamp36 Weeks
View Program

Reloading JavaScript

Fast Refresh is a React Native feature that provides near-instant feedback for changes made to your React components. Enabling Fast Refresh when debugging can be beneficial. Fast Refresh is enabled by default, and you may enable it in the React Native developer menu by toggling "Enable Fast Refresh." Most of your adjustments should be displayed within a second or two once you enable it. 

In-app Errors and Warnings

In development builds, errors and warnings are presented inside your app. 

Errors 

Inside your app, errors are displayed in a full-screen alert with a red background. A RedBox is the name for this type of display. You can manually trigger one using console.error(). 

Warnings 

Warnings will have a yellow background on the screen. YellowBoxes are the name for these notifications. To get more information or dismiss the notifications, click on them. 

A YellowBox can be triggered using console.warn(), much like a RedBox. 

YellowBoxes can be turned off in the console during development. 

disableYellowBox=true; By setting an array of prefixes to ignore, certain warnings can be ignored programmatically: 

import { YellowBox } from ‘react-native’; 

YelloBox.ignoreWarnings([‘Warning:….’[); 

React Native Debugging: Chrome Developer Tools

Select "Debug JS Remotely" from the Developer Menu in Chrome to debug the JavaScript code. http://localhost:8081/debugger-ui will open in a new tab. 

To open the Developer Tools, go to the Chrome Menu and select Tools Developer Tools. You can also use keyboard shortcuts to get to the DevTools (I on macOS, Ctrl Shift I on Windows). For a better react native debugging experience, you might also wish to set Pause On Caught Exceptions. 

One of the drawbacks of utilizing Chrome's DevTools with React Native is that you cannot debug styles or change their properties as you can with web apps. When investigating React's component hierarchy, it is likewise constrained compared to React's devtools. 

Safari Developer Tools 

You do not need to enable "Debug JS Remotely" to debug the iOS version of your app with Safari. 

  1. In Safari, go to Preferences Advanced and enable the Develop menu. "Show Develop menu in menu bar" should be selected. 
  2. Select the JSContext for your app: Develop -> Simulator -> JSContext 
  3. Safari's Web Inspector, which includes a Console and a Debugger, should open. 
  4. Although sourcemaps are not enabled by default, you can enable them by following these instructions or seeing this video and setting break points in the proper places in the source code. 
  5. A new JSContext is created each time the app is reloaded (using live or manually reloading). You can avoid manually selecting the newest JSContext by selecting "Automatically Show Web Inspectors for JSContexts."

React Developer Tools for Debug React Native

You must use the desktop app to debug React Native using React's Developer Tools. Simply use the following command to install it globally or locally in your project: 

yarn add react-devtools 

or npm: 

npm install react-devtools --save 

After that, run yarn react-devtools to activate the app. 

For these two reasons, React's Developer Tools may be the greatest tool for debugging React Native: 

  • It makes it possible to debug React components. 
  • It allows you to debug React Native styles (my favorite aspect of these development tools!). This feature is included in the latest version and works with the inspector in the developer menu. Writing styles used to be a pain, and you had to wait for the app to reload to see the changes. Now we can debug and implement style properties without reloading the app to see the results. 

Except for layout, basic state, and characteristics: 

  • Debugging JavaScript is not possible. 
  • Console logs are missing. 
  • There are no breakpoints or exclusions. 

Although it works with emulated and real devices and is cross-platform, it is a highly specialized debugger. If I needed to debug my layout or determine where a component was getting props wrong, I would use this. 

The redeeming grace is that it also sets the highlighted component as a variable in Chrome Inspector, allowing you to dump the property's state there. It is quite a clever trick. 

Conclusion

This article teaches us about the React Native debugging, Debugger tool, its installation method, how it works, use-cases, and essential capabilities. It will undoubtedly make any React Native developer's life easier, more productive, and more efficient. Additionally, your apps will be faster and have fewer issues. 

We strongly advise you to use the React Native Debugger instead of the Chrome Dev Tools because it contains a set of key capabilities that will significantly speed up your work. 

You can reinforce your resume as a full-stack developer by pursuing courses like Full Stack Software Development Bootcamp and AI Powered FSD Course by IIITB. These courses impart the in-demand full-stack development skills that help you explore outstanding job opportunities like full-stack developer, frontend developer, backend developer, and UI developer.

Boost your software engineering skills with our top programs. Explore the courses below to find the right fit

Master in-demand software skills with our specialized courses. Explore your options below to upskill today

Frequently Asked Questions (FAQs)

1. How do I debug in React Native?

2. How do I use React Native debugger with Expo?

3. How do you see logs in React Native?

4. How do you debug React Native apps using Expo and Vscode?

5. Where does React Native debugger install?

7. How do I open React Native debugger Windows?

Pavan Vadapalli

899 articles published

Get Free Consultation

+91

By submitting, I accept the T&C and
Privacy Policy

India’s #1 Tech University

Executive PG Certification in AI-Powered Full Stack Development

77%

seats filled

View Program

Top Resources

Recommended Programs

upGrad

AWS | upGrad KnowledgeHut

AWS Certified Solutions Architect - Associate Training (SAA-C03)

69 Cloud Lab Simulations

Certification

32-Hr Training by Dustin Brimberry

View Program
upGrad

Microsoft | upGrad KnowledgeHut

Microsoft Azure Data Engineering Certification

Access Digital Learning Library

Certification

45 Hrs Live Expert-Led Training

View Program
upGrad

upGrad KnowledgeHut

Professional Certificate Program in UI/UX Design & Design Thinking

#1 Course for UI/UX Designers

Bootcamp

3 Months

View Program