react dev tools Flashcards

(46 cards)

1
Q

What does the ⚛️ badge on a component in the Components tab indicate?

A

The component is currently highlighted/selected. The badge confirms React DevTools has identified it as a React component in the tree.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you force-trigger a re-render of a component from DevTools without changing props or state?

A

Select the component in the Components tab and click the ‘Force update’ button (circular arrow icon) in the top-right toolbar.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the difference between ‘Highlight updates when components render’ and the Profiler’s flamegraph?

A

Highlight updates gives a live, real-time overlay showing which components re-rendered (color-coded by frequency). The Profiler flamegraph is a post-hoc, recorded snapshot showing render durations per commit.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you inspect the actual fiber node for a selected component from the browser console?

A

Select the component in the Components tab, then in the console type $r — React DevTools exposes the component instance (class) or the last rendered value (function component) as $r.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does $r return for a function component vs a class component?

A

For a function component $r is the fiber’s stateNode or a synthetic object with hooks. For a class component $r is the actual class instance, giving you access to this.state, this.props, and methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How can you access the underlying DOM node for a selected React component in DevTools?

A

After selecting a component, its associated DOM node is stored as $0 in the Elements panel. Alternatively, inspect the component and look at its ref or use ReactDOM.findDOMNode($r) (class components only, deprecated).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What profiler metric is ‘base duration’ and how does it differ from ‘actual duration’?

A

Base duration is the estimated time to re-render a subtree without memoization (worst case). Actual duration is how long the render actually took, benefiting from bailouts like React.memo and shouldComponentUpdate.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Why might a component show ‘Did not render’ in the Profiler flamegraph?

A

It was part of the commit but bailed out early — e.g. React.memo, PureComponent, or shouldComponentUpdate returned false, so React skipped re-rendering that subtree.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does a tall, narrow bar in the Profiler flamegraph indicate versus a wide, flat bar?

A

Tall/narrow: the component itself took significant time but has a shallow subtree. Wide/flat: the component has a large subtree but individual render times are fast. Width = total inclusive time, height is not used for duration — color indicates self time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you record why each component rendered in the Profiler?

A

In Profiler settings, enable ‘Record why each component rendered while profiling’. This adds a ‘Why did this render?’ section to each component in the flamegraph, listing changed props, state, hooks, or parent re-renders.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the three reasons React DevTools can report for a component re-rendering?

A

1) Props changed, 2) State or hooks changed, 3) Parent re-rendered (the component is not memoized or memo comparison returned true).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you edit a component’s props live in the DevTools Components tab?

A

Select the component, then in the right panel find the Props section — values are editable in-place. Click a value and type a new one. Changes are immediately reflected in the UI.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Can you edit useState values directly in DevTools?

A

Yes. In the Components panel, expand the Hooks section. State values managed by useState appear as editable fields — clicking them lets you change the current state value live.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How does DevTools display useReducer state vs useState?

A

Both appear under the Hooks section. useState shows as ‘State: <value>'. useReducer shows as 'Reducer: <value>' (in v4+). Neither shows the dispatch function — only the current state value.</value></value>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do you distinguish between multiple useState hooks in DevTools when they don’t have names?

A

They appear in hook call order. To give them readable names, use the ESLint plugin eslint-plugin-react-hooks or annotate with a custom hook name. DevTools v4.18+ can infer names from variable names via source maps.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the ‘Ranked chart’ view in the Profiler and when is it useful?

A

Ranked chart shows all components that rendered in a commit sorted by self render time, descending. Useful for immediately identifying the slowest individual components in a commit without visually scanning the flamegraph.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How do you identify unnecessary re-renders with DevTools?

A

Enable ‘Highlight updates’, then interact with the UI. Components that flash frequently without user interaction are suspect. Cross-reference in the Profiler with ‘Why did this render?’ to confirm prop/state identity issues.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What does the ‘Strict Mode’ double-invoke behavior look like in DevTools Profiler?

A

In development with StrictMode, React intentionally renders components twice. The Profiler may show doubled render counts. React DevTools v4.18+ grays out the intentional second render to reduce confusion.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

How do you filter components out of the Components tree in DevTools?

A

Click the filter icon (funnel) in the Components toolbar. You can filter by component name (regex), component type (host/class/function/memo/forwardRef), or hide components from specific packages (e.g. node_modules).

20
Q

How do you search for a specific component in a large tree?

A

Use the search bar (Ctrl/Cmd+F) in the Components tab. It accepts plain text or regex and highlights all matching components, letting you cycle through them.

21
Q

What is ‘component stacks’ and how does DevTools help with them?

A

Component stacks are the React-specific equivalent of a JS call stack, showing which components rendered the failing component. DevTools enhances error boundaries and console errors with clickable component stacks.

22
Q

How can you jump from a component in DevTools to its source code?

A

Click the </> (source) icon in the Components tab toolbar while a component is selected. This opens the component’s source file in the browser DevTools Sources panel (requires source maps).

23
Q

What does the ‘Suspend’ boundary indicator look like in DevTools, and what does it tell you?

A

Suspended components show a clock/hourglass icon in the tree. The nearest Suspense boundary is highlighted, telling you which boundary caught the suspension and what the fallback hierarchy looks like.

24
Q

How do you inspect context values consumed by a component?

A

Select the component in the Components tab. In the right panel, the Context section shows all context values the component consumes, with their current values and the provider component name.

25
What happens to context display if a provider is filtered out of the component tree?
The consumed context value is still shown in the consumer's detail pane, but the provider component won't appear in the tree. You may need to disable filters to trace the full provider chain.
26
How do you profile an app's initial mount (not just updates)?
Click 'Start profiling' before the component mounts — e.g. before navigation or before the React root is rendered. DevTools records the initial mount commit as the first entry in the timeline.
27
What are 'interaction traces' in the legacy Profiler API and why were they deprecated?
Interaction traces (`unstable_trace`) were a way to label user interactions and correlate them with commits. They were deprecated because the React team replaced them with the Scheduler and concurrent features tracing in the new Profiler API.
28
How do you export and import a Profiler recording?
In the Profiler tab, use the 'Export' button (down arrow) after recording to save a JSON file. Use 'Import' (up arrow) to load it later — useful for sharing performance recordings across teams.
29
What is the significance of commit bars at the top of the Profiler timeline?
Each bar represents one React commit. Bar height correlates with commit duration. Clicking a bar shows the flamegraph for that commit. A cluster of tall bars indicates a performance-heavy interaction.
30
How does React DevTools handle concurrent rendering / transitions differently from legacy renders?
In concurrent mode, DevTools shows deferred/interrupted renders separately. The Profiler can show which renders were part of a transition (startTransition) vs. urgent, and whether renders were interrupted and restarted.
31
What DevTools feature helps you see which components are wrapped in React.memo?
The Components tree shows a 'Memo' badge on memoized components. You can also filter the tree to show only Memo components using the component type filter.
32
How do you find all components using a specific hook (e.g., useEffect) in DevTools?
Currently DevTools doesn't have a 'find by hook' search. However, you can inspect individual components' Hooks section. For large apps, a custom Babel plugin or React's upcoming component tree search improvements are better options.
33
What is the 'Timeline' tab in React DevTools (v4.18+) and how does it differ from the Profiler?
The Timeline tab (part of Profiler) shows a chronological view of React's scheduling work including lanes, tasks, and React root activities over real wall-clock time. The Profiler flamegraph is per-commit; Timeline shows the full scheduling picture including concurrent features.
34
How does DevTools indicate a component is a ForwardRef component?
It renders in the tree as `ForwardRef(ComponentName)` or just `ComponentName` if the inner component has a displayName set. You can set `Component.displayName` to customize the label.
35
How do you give anonymous components readable names in DevTools?
Set `Component.displayName = 'MyName'`. For anonymous arrow functions, either name the variable (`const MyComp = () => ...`) with source maps enabled, or assign displayName explicitly. memo and forwardRef wrappers inherit the inner component's displayName.
36
What's the quickest way to get to a React component in DevTools from a DOM element?
Right-click the DOM element in the browser and select 'Inspect' to open Elements panel, then switch to the Components tab — DevTools auto-selects the nearest React component that owns the element.
37
How do you inspect error boundary state in DevTools?
Select the error boundary component. Its state will show `hasError: true` and the `error` state value when an error has been caught. You can also manually set `hasError` to `false` in DevTools to reset the boundary without reloading.
38
What causes the 'Maximum update depth exceeded' error and how does the Profiler help diagnose it?
It's caused by setState inside an unguarded render or useEffect. The Profiler will show a very large number of commits in rapid succession. 'Why did this render?' will show state changing every commit, pointing to the offending component.
39
How do you use DevTools to debug a component that's not receiving the right context value?
Select the consumer component and check the Context section. Then find the provider in the tree (search by context displayName or provider component name) and inspect its value prop to see what it's providing.
40
What is `window.__REACT_DEVTOOLS_GLOBAL_HOOK__` and should you ever use it directly?
It's the interface React uses to communicate with the DevTools extension. You generally should not use it directly — it's an internal API. However, it can be used to detect if DevTools is installed: `window.__REACT_DEVTOOLS_GLOBAL_HOOK__?.isDisabled === false`.
41
How do you profile a production build with React DevTools?
React DevTools works with production builds only if you use the 'profiling' build of React (`react-dom/profiling`). Standard production builds strip profiling instrumentation. Configure your bundler to alias `react-dom` to `react-dom/profiling` for profiling builds.
42
What is the react-devtools standalone package and when would you use it?
It's an Electron app (`npm install -g react-devtools`) that connects to React apps via a `