How to Use React Developer Tools
Tags: javascript, webdev, tutorial, react
Published: 2021-11-23 08:42:38

---
title: How to Use React Developer Tools
published: true
date: 2021-07-10 12:27:58 UTC
tags: javascript, webdev, tutorial, react
canonical_url: https://www.upbeatcode.com/react/how-to-use-react-developer-tools/
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g76y28djm7ojhikdk6z1.png
---
One tool that comes in handy when developing React applications is React Dev Tools. It allows you to inspect React component hierarchies in the browser developer tools. And in this guide, we're gonna learn how to use it!

# How to Install React Dev Tools

To start using React developer tools. We need to install it as a browser extension. Click one of the links below to install it. Currently, the extension is supported by these browsers:

- [Chrome](https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi?hl=en)
- [Firefox](https://addons.mozilla.org/en-US/firefox/addon/react-devtools/)
- [Edge](https://microsoftedge.microsoft.com/addons/detail/react-developer-tools/gpphkfbcpidddadnkolkpfckpihlkkil)

Once you have developer tools installed. It's time to start using them.

# Opening React Dev Tools

To open the extension. Right-click anywhere in the browser window and click on Inspect. Additionally, you can open it by pressing F12. This will open browser developer tools with all the usual tabs like Elements, Console, etc.

![How to open React developer tools](https://www.upbeatcode.com/ba00a51d539d413b3f113413106991d5/d18c522e0321aae4902f6edd218daa06.gif "How to open React developer tools")

Because we installed React dev tools extension. We get access to 2 new tabs:

- **Components** - Used for inspecting the component tree
- **Profiler** - Used for performance monitoring

# Inspecting Component Tree

The main purpose of `Components` tab is to show us the structure of the React application. The structure shows how are all the components nested. In addition, we also get other useful information about the components. E.g. props, state, context, functions, etc... We'll talk more about them later. But for now - let's see how can we find the component we need inside the component tree.

## Locating Component

The are multiple ways to locate the component inside React dev tools. The most simple one is to use the arrow in the top-left corner. Then simply point and click on the component we want to inspect.

![How to locate component in react developer tools](https://www.upbeatcode.com/93f3b3d51defaab2991847b162c31141/d11048f6f66151e8f220d2c859b56b5e.gif "How to locate component in react developer tools")

If we know the name of the component we want to locate. We can use a built-in search bar that will find and highlight components for us. This is especially useful if we have a component tree that is deeply nested.

![How to search for a component in react developer tools](https://www.upbeatcode.com/22be46f9622fe40608acf531b76add8a/searcxh.gif "How to search for a component in react developer tools")

The one useful thing to remember is this. `Components` and `Elements` tab interact with each other. If we select any component in `Components` . It will also get selected in `Elements`. It also works another way around. In the example below, selecting button will automatically select `Button` in `Components` tab.

![How react developer tools interact with elements](https://www.upbeatcode.com/dcab246f92266d9f2014260e6b1c210f/elements-interaction.gif "How react developer tools interact with elements")

## Debugging Component

Most of the time, we want to see what's happening inside our components. Using React developer tools, we can see a lot of useful information about the component. We can also see, how is the information changing as we interact with the application.

In the example below, we can see state changing as we're adding or removing new items. This also works another way around. This means we can manipulate state within developer tools, without any interaction with the UI. In the example below, we're removing items. By modifying the component state directly in the dev tools.

![How to manipulate state using react developer tools](https://www.upbeatcode.com/711679c6f0188025e57969d9aab502ab/state.gif "How to manipulate state using react developer tools")

Components tab is also connected to Console. Once we have a component selected, we can switch over to `Console` and type `$r`. It will give us all the information we see in the `Components` tab.

This way, we can interact with the component using our beloved console. In addition, we can also call functions that the component has access to. I believe every front-end developer will find this handy.

![How to log component information to console in React developer tools](https://www.upbeatcode.com/87ef3864afa8d47d7ef0c32d6a772191/console.gif "How to log component information to console in React developer tools")

Now that we know how to inspect our components. We can quickly find out if there are any issues within them. And if there are, it's time to find out why.

## Inspecting Source Code

React developer tools make it easy to inspect source code directly in the browser window. Preventing us from constantly switching between code editor and browser. All we need to do is select the component. And click on the `<>`. This will open up the corresponding file, where we can see what's wrong with the code.

![How to show source code in React developer tools](https://www.upbeatcode.com/a9e2a8b29708d7b96a194ad7415d2965/sourcecode.gif "How to show source code in React developer tools")

We get this feature by default if we're using [create-react-app](https://create-react-app.dev/) or [Next.js](https://nextjs.org/). But if you can't see the original code of your component, you'll need to add [babel-plugin-transform-react-jsx-source](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-jsx-source) to your Webpack configuration.

Using these tools, we can easily observe how our application behaves. And fix the issues as they're coming up. When the application is stable and bug-free. It's time to optimize its performance. And for that, we can use `Profiler`.

# Monitoring Performance with Profiler

`Profiler` shows us how long it takes to render each component of our app. We can identify what component is slowing down our application. And of course, improve its performance!

In this example, we can see that rendering [material-ui](https://material-ui.com/) Button is taking most of our rendering time. Not that it's slow. But if we want to make our app even faster. We can replace it with custom `Button` component.

![How to use profiler in react developer tools](https://www.upbeatcode.com/216c563101b77bc4e7dbc741476030c7/profiler.gif "How to use profiler in react developer tools")

It also shows if the component was rerendered and what triggered the rendering. It's worth checking out if there aren't any unnecessary re-renders happening in our app. And if they are, we most likely can optimize them. Making our React website much faster.

# Conclusion

React developer tools come with a lot of handy features that can make our developer experience better. In this article, we showed how to install them. Showcased in what situations and how can we use them.

We also provided useful tips and tricks. Which can make using React developer tools much easier.
New features are constantly added to React DevTools. [React DevTools v4](https://reactjs.org/blog/2019/08/15/new-react-devtools.html) was released in August 2019. Improving performance, Simplified navigation, and support for React Hooks. Since then, React team is continuously working on making this tool better and better!