Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In react-devtools, what do the various highlighting colors of the "highlightUpdates" option mean

I've been using the react-devtools to detect any unnecessary component updates, however I'm not sure I fully understand how it works.

I can identify the various components that got updated by the added borders indicating that they got updated but I'm not sure what the various colors of those borders mean (I've so far seen cyan and light green colors).

like image 667
Adonis K. Kakoulidis Avatar asked Aug 02 '18 07:08

Adonis K. Kakoulidis


People also ask

What do the React developer tools show us?

React Developer Tools is a Chrome DevTools extension for the open-source React JavaScript library. It allows you to inspect the React component hierarchies in the Chrome Developer Tools. You will get two new tabs in your Chrome DevTools: "⚛️ Components" and "⚛️ Profiler".

How do I see state in React Devtools?

Access React components and state from the console Select a component in React DevTools and pop open the console (hitting the Esc key lets you see both at once). Type in $r and you'll have access to the instance of that React component from the console.

How do I inspect React code in Chrome?

Use React developer tools in Chrome By selecting one of the components in the tree, you can inspect and edit its current props and state in the panel on the right. In the breadcrumbs you can inspect the selected component, the component that created it, the component that created that one, and so on.


1 Answers

I'm not familiar with this either, but I'll trace through the code! :)

This is the component that renders the "Highlight Updates" toggle. It calls a changeTraceUpdates method in the main Store which sends a message through the "bridge" to activate the TraceUpdatesBackendManager. Poking around that file, we see a couple of classes with names like "presenter" in them; I assume one of these is what actually draws the border. In particular, TraceUpdatesWebNodePresenter looks related because it defines an array of COLORS. It looks like these colors are chosen based on a "hit" attribute, which a quick search suggests is set by TraceUpdatesAbstractNodePresenter– and gets incremented each time an element is "presented".

Reading between the lines then, I assume this means that components that render less frequently will be outlined with "cool" colors (blue) and ones that render more frequently will be outlined with "hot" colors (red).

like image 71
bvaughn Avatar answered Oct 23 '22 01:10

bvaughn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!