Debugging React Applications with React DevTools
Tags: react, webdev, debug, productivity
Published: 2022-05-17 11:37:18

---
title: Debugging React Applications with React DevTools
published: true
date: 2022-05-17 11:00:20 UTC
tags: react, webdev, debug, productivity
canonical_url: https://www.syncfusion.com/blogs/post/debugging-react-applications-with-react-devtools.aspx
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eys1iq8j78mvdmf7n0tc.png
---

[React](https://reactjs.org/ "React home page") is one of the most popular front-end frameworks today. Just like other frameworks, it has a set of tools for debugging called React Developer Tools (React DevTools). In this article, we’ll go through a few strategies that will help you debug React applications using the React Developer Tools.

## What is React DevTools and how does it work?

React Developer Tools is a browser plugin that provides React-specific debugging features. It is available for [Chrome](https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi?hl=en "React Developer Tools Chrome Extension"), [Firefox](https://addons.mozilla.org/en-US/firefox/addon/react-devtools/ "React Developer Tools Firefox Extension"), and as a standalone app.

![React Developer Tools Chrome Extension](https://www.syncfusion.com/blogs/wp-content/uploads/2022/05/Chrome.png)

It displays the list of the root React components rendered on the page and the subcomponents that are rendered by each source. Ultimately, you can apply this data to find inefficient code or optimize data-intensive components.

## Installation

If you are using a browser other than Chrome or Firefox, you can install the DevTools as a standalone app using the following command.

```
npm install -g react-devtools@^4`
```

After installation, two new tabs, **Components**  and  **Profiler** , appear in the browser on inspecting the webpage in the browser. If you’re on a page without React components, both of these tabs appear gray. If it has React components, they will appear in blue or green.

![Components and Profiler tabs in the React webpage](https://www.syncfusion.com/blogs/wp-content/uploads/2022/05/Installation.png)

## Components tab

In prior versions, navigating through extensive component trees in DevTools was a little cumbersome. But now, there’s a Components tab, which displays the current React component tree and any props, states, or contexts. It also lets you filter components and hide those that you aren’t interested in.

To view this functionality in action, choose a component and see the props, state, and hooks of that component displayed on the right-hand side of the console.

You can hover over any HTML element in the browser to highlight the React component responsible for rendering it. Or click on an HTML element to choose the relevant React component in the tree by selecting the arrow button in the leftmost tab.

### ![Usage of Components tab](https://www.syncfusion.com/blogs/wp-content/uploads/2022/05/Components-tab.gif)

### DevTools adjusts nested indentation dynamically

In an earlier version of React DevTools, deeply nested components required both vertical and horizontal scrolling, making it challenging to track big component trees. DevTools now adjusts nested indentation dynamically to limit horizontal scrolling.

### Restore the last element selected

When you hit Reload when debugging, DevTools restores the last chosen element to its original state.

### Functions

If you’re looking for a specific function, such as a click handler or a callback function, React DevTools has a handy option for you. You can make a function available as a global variable by right-clicking it in the props or state overview.

### ![Declaring a function as global variable](https://www.syncfusion.com/blogs/wp-content/uploads/2022/05/Functions.png)

### Improved support for hooks

Hooks now offer the same degree of support as props and states in version 4, making debugging React apps faster and easier. It’s possible to change values, drill down into arrays and objects, and so forth.

## ![Improved support for hooks](https://www.syncfusion.com/blogs/wp-content/uploads/2022/05/Improved-support-for-hooks.png)

## Profiler tab

The Profiler tab in React Developer Tools allows you to record interactions and measure component rendering. When you’re debugging something complicated, this feature comes in handy with a new “reload and profile” section.

It can keep track of component rendering and re-rendering, as well as the length of time each render takes. When assessing the performance of specific components, this list can be utilized to jump between commits easily.

Follow these steps to use the profiler:

1. First, open a website that’s built with the [profiling build of ReactDOM](https://reactjs.org/link/profiling "How to use profiling in production mode for react-dom GitHub documentation").
2. Then, start recording a session by clicking the red circle.
3. Perform some operations in the application.
4. Finally, press the circle again to end the session. As a result, component-specific timings should appear. ![Usage of Profiler tab](https://www.syncfusion.com/blogs/wp-content/uploads/2022/05/Profiler-tab.gif)

A handy method to understand how components interact is by enabling a highlight when a component is re-rendered. This will offer you a visual representation of how the components react to data changes.

## Step through parents

You can easily debug an unexpected prop value in the newest version of React DevTools by tracing back the origin of a particular prop.

The right pane displays a rendered-by option list that allows you to move across the list of owners to speed things up while debugging. We can see the parent component that renders each child component in our app by clicking on it.

![The rendered by option](https://www.syncfusion.com/blogs/wp-content/uploads/2022/05/Step-through-parents.png)

React DevTools also has an inverse function known as the owners’ tree. It is a list of the items that a particular component renders. This can be an excellent approach to getting a feel for large, unfamiliar React apps.

Double-click a component to see the owners’ tree, then click the **x** button to return to the whole component tree. You can also navigate in the tree to see all children of the component.

## Access components and states from the console

Although most bugs can be found and fixed easily with React DevTools, some debugging is better done via a good old **console.log**. Now you can interact with component instances directly from the console.

Open the console by selecting a component in React DevTools (hitting the escape key lets you see both at once). Then fetch the instance of that React component from the console by typing **$r**. ![Accessing components and states from the console](https://www.syncfusion.com/blogs/wp-content/uploads/2022/05/Access-components-and-state-from-console.png)

## Jump into source view

Babel includes a plugin that adds the source property to all JSX elements. With this Babel plugin support, you can now directly navigate to the browser’s source view, where you can inspect, set breakpoints for, and modify the code. Although it slows down the application slightly, it does perform well in development mode.

Install **babel-plugin-transform-react-jsx-source** , add it to your **.babelrc** file. Then, restart your dev server to use this capability. You’ll notice a new option when you right-click a component in the component tree: **Show component name> source**.

## Interaction tracking

Interaction tracking is supported by React DevTools. This is a programmatic API that allows you to label and track the performance of various events in your app. For example, button clicks. It would be helpful to trace these events to obtain timing information and underlying causes for some delayed commits.

Please do keep in mind that this API is removed with React 17.

## Conclusion

Debugging is usually an interactive process in which you interrogate an application to understand why the behavior doesn’t match expectations. When debugging React, it is better to determine what you’re debugging first. Then, you can decide the techniques to use based on that.

I hope my article gave you a few insights into debugging React applications with React DevTools.

Thank you for reading!

The [Syncfusion React JS](https://www.syncfusion.com/react-ui-components "Syncfusion React JS UI components") suite offers over 70 high-performance, lightweight, modular, and responsive UI components in a single package. It’s the only suite you’ll ever need to construct a complete application.

For questions, you can contact us through our [support forum](https://www.syncfusion.com/forums "Syncfusion support forum"), [support portal](https://support.syncfusion.com/ "Syncfusion support portal"), or [feedback portal](https://www.syncfusion.com/feedback "Syncfusion feedback portal"). We are always happy to assist you!

## Related blogs

- [Implementing React Custom Hooks: A Complete Guide](https://dev.to/syncfusion/implementing-react-custom-hooks-a-complete-guide-455k "Blog: Implementing React Custom Hooks: A Complete Guide")
- [Top 5 React Lazy-Loading Libraries for 2022](https://dev.to/syncfusion/top-5-react-lazy-loading-libraries-for-2022-1d46 "Blog: Top 5 React Lazy-Loading Libraries for 2022")
- [Everything You Should Know About React 18](https://dev.to/syncfusion/everything-you-should-know-about-react-18-elo "Blog: Everything You Should Know About React 18")
- [Unit Testing in React with Jest and Enzyme Frameworks](https://dev.to/syncfusion/unit-testing-in-react-with-jest-and-enzyme-frameworks-1g97 "Blog: Unit Testing in React with Jest and Enzyme Frameworks")