Enter Your Email Address to Watch This Lesson

Your link to unlock this lesson will be sent to this email address.

Unlock this lesson and all 832 of the free egghead.io lessons, plus get React content delivered directly to your inbox!



Existing egghead members will not see this. Sign in.

Just one more step!

Check your inbox for an email from us and click link to unlock your lesson.



Analyze React components with MobX-React devtools

1:36 React lesson by

The MobX React devtools can be used to analyze when and why React components are re-rendered. They offer three features: 1) visualize when components re-render, 2) show the dependency tree of a component, to see which data it's rendering depends upon, and 3) log in detail which data is changed by your actions, and how these changes propagate through the application.

Get the Code Now
click to level up

egghead.io comment guidelines

Avatar
egghead.io

The MobX React devtools can be used to analyze when and why React components are re-rendered. They offer three features: 1) visualize when components re-render, 2) show the dependency tree of a component, to see which data it's rendering depends upon, and 3) log in detail which data is changed by your actions, and how these changes propagate through the application.

Before we continue, I want to introduce you first to the MobX React DevTools. These tools are a very valuable asset to analyze what MobX is doing. We'll use them throughout the course, so let's use them.

In a real project, you can import them as devtools from the MobX React DevTools package. In this gs.bin, however, we have loaded them as UMD module so we can import them from the global scope. The only thing we need to do after importing them is to inject them somewhere in our component tree.

There they are. We have this new toolbar, which introduces three tiny buttons. The first one, if enabled, makes sure that MobX shows all the renderings that are happening on the screen per components. For example, if you press a button, this component is rerendered, and we can see how often it has been rendered and how long it took to render this component.

The second button can be used to analyze when a component will rerender. We now have the selection mode, and we can click components. We get a report about which observables are being observed by this component. Our counter component observes one field, which is the count fields of the first observable object we have created.

Finally, there is this button that enables extensive logging about everything that happens in MobX. If we open the browser's console, and we enable the log, and we press the buttons, we see exactly what happens. Our count has been updated from four to five. Based on that, MobX has determined that our counter component needs to rerender, which happens after that.

These are the MobX DevTools. Use them to your advantage.



HEY, QUICK QUESTION!
Joel's Head
Why are we asking?