Sub topic 2
Editing Values Live to Reproduce Bugs
Assume you can write React function components, use props and useState, and run a React app in development mode. React Developer Tools lets you change a mounted component without editing its source code. This helps you test a hypothesis quickly.
Edit values in Components
Open the Components tab and select a component. Expand its props, state, or hooks. Double-click an editable value, enter a replacement, and press Enter. React updates the mounted tree immediately.
Use this to test cases such as:
- An empty string or missing value.
- An unusually large count.
- A different selected item.
- A boolean switched from
falsetotrue.
These changes are temporary. A reload or normal application update can restore the original values. Record the failing value before you reload.
Find components quickly
The component tree can become large. Use the search box to find a component by name. Use component filters to hide noise such as host elements, higher-order wrappers, or components from libraries. Select the matching result to inspect it.
Use the Console and source links
With a component selected, switch to the browser Console. React Developer Tools exposes that component as $r.
$r.props;
$r.type;$r.props shows the selected component's props. $r.type shows its component function or class. The selected component also has a source link in DevTools when source mapping information is available. Open it to connect the runtime instance to the file that defines it.
Highlight unexpected updates
Turn on Highlight updates when components render in the Components settings. Interacting with the app then flashes components as React renders them. A component that flashes during an unrelated interaction may be receiving changing props or state.
Highlighting shows where updates occur, but not why they occur. Use the Profiler for that detail.
Choose the right build
| Build | Useful for |
|---|---|
| Development | Inspecting components and debugging behavior |
| Production | Measuring realistic user performance |
| Production profiling | Measuring production behavior with Profiler data |
Development builds include helpful debugging information but can run slower. Use a production profiling build when you need production-like measurements and your build setup supports it.
Record a profiling session
Open Profiler, select the application, and click Record. Perform one focused action, such as selecting an item, then stop recording. React Developer Tools displays the commits made during that interval. Select a commit to inspect the components that rendered and the time they used.
Exercise
A list item flashes when an unrelated selection changes. What should you do next?
Show answer
Record that interaction in the Profiler, select the item in the commit, and inspect its render reason and changing props.