r/reactjs • u/RadioLast5093 • 11h ago
Resource How much prop drilling is in popular React codebases? I measured 104 repos: 653 props carried through components that never read them
Everyone agrees prop drilling is bad and nobody agrees on where it starts, so I tried to define it strictly enough for a tool to find it.
The definition I ended up with: a prop goes through 3 or more components that do nothing with it except hand it to a child. Each of those components has to declare it, type it and forward it, and none of them needs it.
What does not count, because these were the false alarms:
- The component reads the prop for anything at all, even one condition
- It binds the prop to an event of a child, like `<Button onClick={onSave} />`. That is using a callback, not passing it along
- It spreads the whole props object down. That is a wrapper, a different problem
- The child comes from a library. The chain is only followed through components of the project itself
I ran this over 104 of the most starred TypeScript repos in the AI ecosystem, resolving components across files with the TypeScript compiler.
- 55 of the 104 had at least one drilled prop
- 653 drilled props in total, starting from 448 components
- The longest chains were 6 components deep. One example: `externalLink` enters at `InspectorReviewsView` and passes through `ReviewRuns`, `ReviewRunHistory`, `ReviewSummaryCard`, `GithubInlineComments` and `InlineCommentList` before `InlineCommentRow` finally reads it
- shadcn/ui: zero
Two things I did not expect:
- Drilling comes in bundles. When one prop goes down a chain, five more usually go down the same chain. The 653 props are really about 450 places, and often 3 or 4 structural decisions per repo. It is one fix, not twenty.
- The fix was almost never "add a context". In most chains the top component could simply render the bottom one and pass it as `children`, and the four components in between would stop knowing about the value.
A sample of these findings was checked by hand against the source, which is where the callback-binding rule above came from: the first version counted `onClick={onSave}` as a pass-through and it was wrong.
Per-repo numbers, prop drilling has its own column: https://github.com/PatternVoid/unknot/blob/main/LEADERBOARD.md
The tool is open source and I wrote it: https://github.com/PatternVoid/unknot. `npx unknot --rule prop-drilling` lists the chains in your project, with files and lines.
Where would you draw the line? Is 3 pass-through components too strict, or too lenient?