Optimizing apps using React Developer Tools
This article aims to provide an easy-to-follow tutorial on the basics of optimizing React apps using React DevTools. We will put together a simple unoptimized version of the ToDo app and gradually improve it while uncovering React DevTools’ functionality.
What is React DevTools?
React Developer Tools is a set of tools that represent your app’s internals in a convenient fashion. It offers a visual representation of the component hierarchy, real-time info on state and props updates, and profiling tools to inspect when and why components render.
How to install React Developer Tools
React DevTools come in the form of a browser extension for Chrome, Edge and Firefox, and as an npm package.
In this tutorial, we’ll debug with Chrome. Download the extension from the Chrome Web Store to get started.
For other browsers like Safari etc., install the react-devtools npm package
and inject the script into your website’s <head> tag.
After installing the extension, you should see Components and Profiler panels in your browser’s DevTools:
React Developer Tools, Components tabReact DevTools: Components tab
I’d like this tutorial to be practice-driven, so let’s put the tools to the test by analyzing our simple app. The app is bootstrapped with create-react-app, so feel free to recreate the structure and copy code pieces provided in this article. It looks as follows:
Simple ToDo List app conceptOpen Chrome Developer tools, and you will see two new tabs: Components and Profiler.
React Developer Tools, Components tabThe Components tab is Chrome’s Elements Inspector look-alike but for React. Highlight an element in the hierarchy tree (left panel) to see its props, hooks, and other information (right panel).
You can change props in real time like in the screenshot below. If the prop is a function, clicking redirects to the Sources panel to the respective line of code. This makes testing edge cases easier.
Hover over a page element using the cursor icon left of the search field to highlight its component in the React DevTools tree. To reverse it, select a component in the tree and click the eye icon in the right panel to highlight the element in the Elements tab.
