React Dev Tools In Firefox
Tags: devtools, webdev, react, javascript
Published: 2023-07-15 09:06:41

Debugging React apps through an IDE like VS Code or WebStorm handles one aspect of inspecting your React app. The other main aspect is seeing what is happening in your browser as your app runs. Fortunately, we can see what is happening in the browser using the React Dev Tools extension.

## The React Dev Tools extension

This extension allows developers to examine the React tree of components and to profile aspects of the application. For example, you can set up the tool to see when components render as the state of the application changes. This information cannot be easily seen from within an IDE by looking at the code.

## Installing the React Dev Tools Extension In Firefox

To get started, go to the Mozilla add-ons site. You should see something similar to this page:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pscxatdwp2a320xhq6mj.png)

Click the _Add to Firefox_ button to install the extension.

You will be prompted to allow the extension to access data for all websites, input data to the clipboard and more. You’ll need to click the _Add_ button to continue the installation. The prompt should look something like this:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p4b1nxeobldmx0s6q3d0.png)

Lastly, you will see a prompt asking you to allow the extension to run during an InPrivate window session. It is a good idea to allow this so you can debug your React app without worrying about the site being affected by caching. The prompt should be similar to this:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mwilt31yray3c9zfdcbp.png)

Check the check box and click _Okay_ to continue.

## The React Dev Tools Icon

Now that you’ve installed the extension, you should see a greyed-out React icon in the top right-hand corner of your browser. It should look like this (highlighted in orange):

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m9fq0k6tvc8ve3nzjd8j.png)

The icon is greyed out like above because the site you are currently on is not a React site. We need to browse a React site to test if the extension is working.

A good example of a React website (when writing this article) is the task management application, Asana. If you go to [this](https://asana.com) website, you will see the extension become coloured, looking like this:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7pbspmganpq2cuhiu8fq.png)

If you left-click this icon, you will see a message appear saying that the page is using a production build of React. This means the site is optimised by removing debugging information, optimising assets and minifying the code. The message should look something similar to the image below:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k89hg2m5mfdlxjsqdbft.png)

A quick way to tell if you are viewing a site that is the production build is to note the colour of the extension icon itself. The black background is the indicator that the site is a production build. A red background indicates a development build.

Here is an example of the icon on a development site:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qt9fe15edq9tfhzodskr.png)

## Inspecting A Development Build Of A React Site.

Now that we’re browsing a development version of a React site, we can click the icon and get more information. The prompt should be similar to this:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5c3myvzxwyw099isu3qt.png)

The information mentions that the current build is suitable for debugging but releasing to production (which is what we want to see). It also mentions that when opening the developer tools, we should see two new tabs: Components and Profiler.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f8zasf7713hw3h14l3v4.png)

## The Components Tab

Opening the developer tools and clicking the Components button opens the components tab. This tab shows the list of React components in your current view. 

To view a particular component's details in the components tab, you can use the select tool to select the component from the view. 

This is the select icon described above: 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5t9n3iygp8pxeafgsx8d.png)

If you hover over the icon, you get some more information:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l6pj3c7m1j95b46xunkf.png)

Following the prompt's advice, we can click the select icon and select an element on the page to inspect it.

In the image below, I have selected a button in my application:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aveopmgzlwys59fdj818.png)

### Breaking down the components tab into sections

The view can be broken down into four distinct areas. The orange area is the tree view of all the components in the current view. The green area represents the properties (props) of the currently selected element. The purple area designates the hooks of the selected element, and the blue area shows the parent tree of how the selected element was rendered.

You can think of the component view as a key/value (master/detail) pair with the key being the component selected on the left-hand side and the value being the information about the key on the right-hand side.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r292rhp215v9copwgdgo.png)

This view may change depending on the selected element. The above description is an overview of what you might be looking at.

On the right-hand side of the components tab, you will see the following icons:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/piypylkwp1vrzibsny2j.png)

### The stopwatch icon

The stopwatch icon is used to suspend components. To do this, the component that you’ve selected will need to be within a Suspense container, or you will get the following message:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5m25b1rfb04gc1em8f3x.png)

You can learn more about suspense in my other how-to articles:

» [Code splitting with lazy and Suspense in React](https://bernieslearnings.com/code-splitting-with-lazy-and-suspense-in-react/)

» [Suspense without lazy in React](https://bernieslearnings.com/suspense-without-lazy-in-react/)

» [Lazy loading and Suspense in React](https://bernieslearnings.com/lazy-loading-and-suspense-in-react/)

» [Rendering a list of lazy components in React](https://bernieslearnings.com/rendering-a-list-of-lazy-components-in-react/)

### The eye icon

The eye icon, when clicked, will take you to the corresponding DOM element. For example, I wrap an _Image_ component with properties such as alt text, name, src etc. When I click this component in the component tree and then click on the eye icon, I am taken out of the React Dev Tools to the inspector tab, where the element selected is the _img_ element.

### The bug icon

The bug icon will log the current component to the console. For example, I clicked the bug icon while having my aforementioned Image component selected. This was the output to the console:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ec1q80yrkqzxy14va0pp.png)

### The <> icon

The <> icon will take you to the source code for your component. When selecting a component from the component tree, clicking this icon will take you to the debugger tab, open the source file and highlight the first line of your component. For example, my application has Beds as a component. Clicking the icon shows me this:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1xkqgroqrev5j5vkj8rm.png)

### Component Search Box

You can also use the search box above the component tree to find your components. In the example below, I’m searching for beds, and you can see the number of beds components in the tree and navigate between these matches using the up/down arrow:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/huv480jso2ltb5i4e4p8.png)

### Component Details

The detail side of the component tab will sometimes show checkboxes and other icons, like in this image:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lbhc7dwy5b10sehovtqv.png)

Starting with the hooks, you will notice two icons on the right. 

### The magic wand hook

The first icon (that looks like a magic wand) is a special tool that will update the names of the hooks to match what you’ve named them in your source code. 

Doing this makes it much easier (especially in larger components) to see what is going on in your application. Here is the above image after clicking the wand.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nsp6160g6lt3s0r60spk.png)

You can now see which hook relates to what variable. This makes debugging a whole lot easier. Just note that by doing this, you will face a performance hit from the dev tools. You can see this by hovering over the wand and viewing the tooltip:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jmuc4b54g1zdtl1xnkgd.png)

If the performance hit is too great, I might break my component down further or selectively parse hook names when I need to debug that section specifically.

### The square with dots icon

The next icon is the square icon with the dots to the left and bottom of the square. You will copy the hooks information in JSON format when clicking this icon. This will allow you to view the hooks information in another app (or programmatically process it somewhere else).

Here is an example (in VS Code) of the information copied when clicking the icon with the Beds component selected:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fe2hbds2lo1er7p3abdj.png)

You will also see this icon in the React dev tools tabs. It will always be the _copy to the clipboard_ button and will copy the related information (nearest to the button) to the clipboard.

The checkbox icon on the right-hand side will appear when dealing with boolean values in hooks or props. You can manually toggle between true and false for the hook or prop. 

Doing this lets, you see (in real-time) how your application will look with either value. This can be extremely handy when determining why a specific component isn’t displayed in your app.

## The Profiler Tab

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kwn2g94eedps96tghn7d.png)

When you first click on the Profiler tab in the React Dev Tools extension, you will see something similar to the below image:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vnvabjhwreogi5r7fmod.png)

You can get started by clicking on the blue record button to start recording. Once the profiler is recording, you can use your application as you normally would. When you’ve finished recording the parts of your application you want to profile, come back to the Profiler tab and click the record button again, which will now be a red circle to indicate that the profiler is recording.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y493r6gmkmb6739k16gy.png)

## The Flamegraph Chart

When you’ve stopped recording, you will get a flamegraph like the one below:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o7ws8oebr1exlzsr0o1e.png)

Looking at the top of the chart, you’ll see two numbers. These numbers relate to the commits that occurred when you were using the application. A commit is when React applies changes to the DOM (at least at a high level).

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/px3h6t4p707n4yr9zqwj.png)

In this example, there are ten commits, and we are viewing the first commit.

The blue bar in the chart represents the currently selected commit. If we select the fifth commit, the chart will look like this:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s5v7t07l95f9q8j45w9g.png)

You can move between commits by clicking the back and forward arrows or clicking on the chart bar. The height of the bars represents how long the render took to commit.

### Commit Information

On the right-hand side, you will see the commit information. It will tell you when the commit occurred and how long it took to render it. It will also tell you the scheduler’s priority of the commit. Priority can be one of several different types:

- Immediate
- Normal
- Low
- User Blocking
- Idle

I won’t dive into these priorities in this article. It’s enough to know they exist now and that React has a scheduler to determine when to render or re-render a component.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x0yie12scae6g1q557yx.png)

### Flamegraph explained

In the flamegraph (image below), you can see what components are rendered on each commit and how long each component took to render. The length of the bar represents how long the component took to render. The coloured components are the components rendered during that commit. The grey components did not render during the commit.

Taking our beds component example from earlier, we can see that only the Beds component and its children were rendered during this commit. Unsurprisingly, each of the children components of Beds rendered in less time than Beds did.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/deu1ss6gjcyhqz5nb1nq.png)

Hovering over the Beds component will show you some more information:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qg5iqxjkyvosh28uvzyp.png)

This tells me that the entire duration of the commit was 11ms and that Beds took only 1ms to render.

By clicking on a component, the view will zoom to fit that component to the screen's width. Here is the flamegraph after I’ve clicked the _Beds_ component:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bzh0sd0s8v68w42cyqss.png)

#### Zooming in the flamegraph

You can see that the width of the _Beds_ component is now the width of the flamegraph. You should also note the area I highlighted on the right-hand side. This shows all the times the Beds component was rendered during the recorded commits.

Having this list of times when a component is rendered can highlight issues in your application if a component is being re-rendered too often or more often than you would expect.

To zoom back out to the original view, you can click in the white space under the flamegraph.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8t7vvjbcm1nwnmwsi1qd.png)

#### Saving flamegraph data

If you want to examine your profiling data later or use another tool, you can save the profile to disk as a JSON file by clicking the down arrow (next to the Flamegraph tab). If you want to reload the data later, click the up arrow and import the JSON file into Firefox.

Clicking the circle with a line through it will clear the current profile data ready for you to re-record or import some new data.

## The Ranked Chart

React Dev Tools has a _Ranked Chart_ that serves one specific purpose - to show an ordered list of components sorted by time taken to render. The component at the top of the chart will be the component that took the longest to render.

This chart is useful if you believe that a single component is a bottleneck in the performance of your application.

Here is a Ranked chart for the first commit of the app with the _Beds_ component.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hkhxpwbp298xoozo31vo.png)

Considering the short time the entire commit took to render, it might be difficult to see, but the _View_ and _Beds_ components took the entire time to render. Several other components took little time (compared to _Beds_) to render. These components are the thin green bars you see underneath the yellow ones.

Hovering over one of these green components, you can see more information:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8iu7wo0rhqz4euki5j19.png)

## The React Dev Tools Settings

You can get to the settings screen if you click on the gear icon next to the commit bars:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1p4w25q8inzh8u6dons5.png)

There are four tabs in the settings screen, General, Debugging, Components and Profiler.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8c2obj4slmboafy9do3q.png)

## General Settings

The General tab has three options:

1. To set a light or dark theme (or follow the system settings)
2. To display the charts in a compact and comfortable fashion (the height of the component bars change along with some extra spacing when using comfortable mode)
3. Highlighting components when they render

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k9nd4o913lmq1ccsjf36.png)

If you select Dark as the theme, the settings screen will look like this:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7k5c84ltpvhdviy2oibd.png)

And the Flamegraph will look like this:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3ekf9vh676h5skm7ihyx.png)

The previous examples used the compact display. If you change this setting to comfortable mode, the Flamegraph will look like this:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1sflp6vwro19rscc805r.png)

If you check the checkbox to highlight components when they render, you will see blue boxes outlining your components when they render. This can be very useful if a component is rendering at a strange time. 

For example, if your menu re-renders every time a character is typed or a button clicks, then this could mean you unintentionally have some kind of state tied to the menu.

Here is an example of the highlight that occurs once I click the add bed button in my app:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zeotdj1tx9vk02lqqpp6.png)

## Debugging Settings

The _Debugging_ tab has four settings:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yxtzgjjexffvq2qpv6ej.png)

### Component Stacks

Appending component stacks to console warnings and errors. This refers to what is shown in the console when you use console.warn() and console.error() to display console messages. An example of console.warn() with the component stacks appended is below:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hl5y7761c7hr8agacz5j.png)

And an example of using console.warn() without the appended component stacks:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/znuprbgdbouoit44520t.png)

### Show inline warnings and errors

This refers to the symbols placed beside component names in the stack. The example below shows a warning for the _Beds_ component:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h5wz6gq4hb7kh641gk0u.png)

You can see that the _Beds_ component shows the yellow warning symbol. The search bar also has an icon followed by the number 2. This tells us that there are two warnings on the page now. You can cycle between the errors using the up and down arrows.

### Break on warnings

You can use the break-on warnings checkbox to pause the execution of the application at the point a warning is raised. Using the above site with the _Beds_ component and the checkbox ticked, we are taken to the _Debugger_ tab and the application is paused on this line:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l309039dackhciwp0lpr.png)

There are clear instructions from the React developers about what to do next. To step out of the function, you can use the up-and-right arrow button in the debugger tools:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y76tc693ezsv1e40z552.png)

Following the instruction to step out of this function we can see this:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ts6mzgu3f9f0xq5otfib.png)

Looking at the source code, we can easily see where the warning has come from (console.warn(‘Message two’)).

### Hide logs during second render in Strict Mode

In React 18, a decision was made so that logs would not be silenced on double renders. This was confusing for some developers trying to debug their applications in React 17.

For example, if a developer placed a log message in a component to test when it gets rendered, it would disappear from subsequent renders (sometimes), making it more difficult to debug.

This checkbox allows developers to go back to the React 17 style of suppressing log messages, which is disabled by default. React 18 will show the subsequent log messages in muted colours.

For example, this image shows React 18 with the checkbox unchecked:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b14cmvzdzck50blmc2cc.png)

Notice how the second log message is slightly duller than the original one.

When the checkbox is checked, the second log message is not displayed and we only see the original message:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ezsj0bzubhb2b0tbbeb3.png)

## Components Settings

The settings' Components tab relates to the Dev Tools' Components tab.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n9v8birx2vcvhauik5qm.png)

### Expand component tree by default

The first checkbox determines if the component tree view starts with all nodes expanded or compressed. The following image shows all nodes expanded:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lehesb9s7xadwrpn7xne.png)

The next image shows when the checkbox is not checked. Therefore not all nodes are expanded:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9kwqu07paoqjs2tfldg1.png)

Notice how the bottom _Card_ element is not expanded. Only the elements leading to the currently selected element were expanded. If you haven’t selected a component, then only the root node will be showing. Like this:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6brxvy4l9lghc8p6oe82.png)

### Always parse hook names from source

The second checkbox: Always parse hook names from source - is another way to show the names of your hooks from your source code in the development tools. By checking this checkbox you won’t have to click the wand icon to show the names, they will all show by default. 

Here is a hooks section without the checkbox checked:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ebi9eczv9gdm9kjba2uz.png)

And here is the same hook section after checking this check box

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dmykmpiq4xv6pfn28lx6.png)

I’ve highlighted in red the hook names (on the left-hand side) and the fact that there is no wand icon (on the right-hand side). Do note the warning that by checking this checkbox, the tools will be slower to run as there is more work to extract these names.

### Open In Editor URL

This section allows developers to click an icon and be taken to the source code of that component. For example, I will enter the default vs code setting (as shown as the placeholder text): _vscode://file/{path}:{line}_

Now, when viewing components, you can see a new icon here:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/80tpaghlgiksfmr8mu6p.png)

When I click on this icon I will be taken to VS Code (you may be prompted for a security warning by your browser) and the file containing the component will be opened.

For example, if I wanted to view my landing page component, I would first select the component like this:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fr2j01okracpqxir2tun.png)

Then, once I’ve selected the component, I would click the Open in editor button from above.

The editor is opened and I am taken to the component in question:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fvo29j67au5j5zx1y1t7.png)

### Hide components where...

The hide components section is a way for developers to reduce the number of components in the tree by use of a filter. By default, the standard HTML nodes are filtered, you can see this in the following image:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k0l6u03pob3ygyqli7jl.png)

All dom nodes are hidden as this rule is switched on (the blue slider to the left of the panel indicates that the rule is in effect.

If we turn off this rule you can see all the dom nodes shown in the React Dev Tools component tree like this:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cr10dlteja51b3xod6cz.png)

You can see the dom nodes, div and img in the screenshot above. They are easy to spot as React components start with capital letters.

The add filter button just allows more filter rules to be applied to the component tree.

## Profiler Settings

The _Profiler_ tab in settings relates to the Profiler tab in the dev tools. There are only two options in these settings:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d1bzeaiy2sq3rw44t7tj.png)

### Record why each component rendered while profiling.

The first checkbox allows the developer to see why a component has been rendered inside the profiler. If we check this box you can see profile information like below:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6l00ypinlm5b2r96a439.png)

In this example, I have clicked on a Card component and the profiler now tells me that this rendered because the props changed.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q5pzvwkjtskgdo9j3dgd.png)

If you click around the different components on different commits, you can see multiple reasons components were rendered. For example, if a component is rendered because its parent rendered, then you would see the following:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tvilpifk65izihbhwlmg.png)

### Hide components below

The second checkbox allows developers to filter out any component that took under a certain amount of time to render. This can be helpful when trying only to find slow components.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/klufcwk6x1am1gyqhpx5.png)

In this example, I’ve set the time to 2ms. Performing the same action as in the previous example, my flamegraph looks quite different.

Changing the hide commits below value will update the profile in real time if you have a profile already recorded. This can be handy for filtering out previously recorded commits.

This should be enough information for anyone to get started with React Dev Tools in Firefox (and even Chrome, as the tools are almost identical).

## Bonus

Did you know that you can access React components from the console? If you select a component in the component tree, you can then go to the console and enter the command: _$r_

This is how you can see all the information about how your component is loaded in the browser.

Take the following example of the Beds component from earlier. I’ve selected the Beds component and entered $r in the console to get this:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uolbpwtcj0qntgdiy3ny.png)

As you can see, there is a lot of information here that you may want to access to debug issues in your applications (or even just to play with programmatically in the console).

Please check out this and all my other articles over on [bernieslearnings.com](https://bernieslearnings.com) Thanks for reading!