Sub topic 6
Finding components with search and filters
This chapter assumes you can open the Components tab and read the component tree. It also assumes you know how to select a component to see its props, state, and hooks. Those steps are covered in the earlier chapters.
A real app can render thousands of components. Expanding nodes by hand is slow, and the tree is full of wrappers, providers, and library internals. The Components tab gives you three ways to cut it down: search, the element picker, and filters.
Searching by name
The search box sits at the top of the Components tab. Type part of a component name and DevTools highlights every matching component in the tree. It also shows a counter such as 2 | 7, which means you are on the second of seven matches.
- Press
Enterto jump to the next match andShift+Enterto go back. - Click the Match case icon to make the search case-sensitive.
- Click the Use regular expression icon to search with a pattern. The pattern
^(Item|Row)$matches components named exactlyItemorRow.
Search matches the name that DevTools displays. An unnamed arrow function passed straight to export default appears as Anonymous, so searching for it by name fails. Give components names, or assign a displayName, to make them findable.
import { memo } from 'react';
const Item = memo(function Item({ label }) {
return <li>{label}</li>;
});Here the inner function is named Item, so the component stays searchable. Without the name, the memoized wrapper would show up as Anonymous.
Picking from the page
When you do not know the component name, start from the screen. Click the Select an element in the page to inspect it icon (the cursor) in the Components toolbar. Then click the part of the UI you care about. DevTools selects the nearest React component that rendered that DOM node and expands the tree to it.
This often beats search, because you describe what you see instead of what the code calls it.
Filtering out noise
Search finds components. Filters decide which components appear at all. Open settings with the gear icon, then the Components section. You can add filters under "Hide components where":
| Filter | What it hides | Typical use |
|---|---|---|
| Type | Components of a kind, such as Host (DOM elements), Context, Memo, or Forward Ref | Hide context providers and wrappers to see your own components |
| Name | Components whose name matches a pattern | Hide a design-system prefix such as `^Styled` |
| Location | Components whose source path matches a pattern | Hide everything under `node_modules` |
Each filter has a checkbox, so you can switch it off without deleting it. DevTools saves filters between sessions and applies them to search too. A hidden component never matches a search.
Filtering changes only the view. Hidden components still render, and their props and state still exist. A filtered-out parent also does not break the parent-child path: its children appear under the next visible ancestor.
A practical routine
- Use the element picker if you start from a visual symptom, or search if you start from a name.
- Hide
node_modulesby location and any provider-heavy types by type. - Search with a regular expression to compare related components, such as
Form|Field. - Select the result and read its props, state, and hooks.
Exercise
You search for UserCard in the Components tab and get no matches, but the card is visible on the page. Name two likely causes and one way to find the component anyway.
Show answer
Likely causes: a filter (by type, name, or location) is hiding the component, or the component is anonymous and displays as Anonymous, so its code name does not match. To find it anyway, use the element picker and click the card on the page. DevTools selects the component that rendered it.