r/reactjs • u/RadioLast5093 • 4d 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?
2
u/Glad_Bite4737 4d ago
The children fix is so obvious in hindsight but I bet 90% of those teams never even considered it, myself included.
3
u/m0rpeth 4d ago
More slop content for me to not read. Cool.
1
u/pVom 4d ago
Prop drilling is only a problem when it's a problem. Context is a hamfisted solution and it affects the reusability of the consumer.
Often prop drilling comes as a result of a trade off between prop drilling and maintaining small, contained and reusable components.
I think it's hard to put a strict rule on it. Prop drilling is more an inconvenience and a DX issue than "bad". It's perfectly reasonable to use it when the trade off is more inconvenient.
Also with AI a lot of these problems aren't really a big deal anymore, it's fast and easy to get AI to drill a prop for you.
1
u/voxalas 4d ago
nitpicking
1
u/allaboutzaid 4d ago
The bundles finding rings true even at my scale — in my small projects, when one prop goes down three levels, two or three more usually go with it, so the chain feels messy long before it's deep. The children fix is the part I'll actually try first, since it doesn't need a new library or a context. Three pass-through components feels like a fair line to me: fewer than that and it's just normal props, but at three you're clearly carrying something the middle components don't care about.