Refactoring React Component Hierarchies to Eliminate Prop Drilling
summary
The gist
In this work, we propose a static analysis method for identifying Prop Drilling instances in a React codebase and eliminating them using two automated refactoring strategies based on Context API and…
In short
The work proposes a static analysis method to find and eliminate prop drilling in React code using two automated refactoring strategies: Component Composition and the Context API. Empirical results show that while depth is less complex, Compound Prop Drillings are common. The Context API strategy successfully refactors 74.9% of identified prop drillings, demonstrating its high potential for improving code maintainability.
Key concepts
- Prop Drilling
- This occurs when data needs to travel through many intermediate components in a React hierarchy just to reach a component that actually needs it. It's done by passing props down through successive components, which makes tracing the data flow difficult and harms maintainability.
- Prop Drilling Depth
- This metric measures how many intermediate components are involved in a single prop drilling sequence. A higher depth means more unnecessary coupling between the source and target components, indicating greater complexity in the data propagation path.
- Compound Prop Drilling (CPD)
- CPD refers to situations where multiple properties are simultaneously forwarded along the exact same path of intermediate components. This increases coupling because changes to any one property might require updating many other properties at that same depth.
- Component Hierarchy Graph (CHG)
- This is a static graph representation of the React codebase that maps parent-child relationships and data flow based on prop passings and forwardings. It allows the method to mathematically model the structure of data propagation across different components.
Terminology used across episodes
This episode discusses
The paper
Refactoring React Component Hierarchies to Eliminate Prop Drilling · Read on arXiv
Department of Informatics, Athens University of Economics and Business · Computer Science and Engineering Department, University of Ioannina
In React front-end development, Prop Drilling is the practice of propagating data through component properties across multiple levels of the component hierarchy. Despite being discouraged by React documentation and characterized as a code smell by recent research, little is known about its prevalence, complexity, and potential for automated refactoring. In this work, we propose a static analysis method for identifying Prop Drilling instances in a React codebase and eliminating them using two automated refactoring strategies based on Context API and Component Composition. The proposed method is implemented as a Nodejs command line tool, ReactRefactor, and empirically evaluated on a benchmark dataset of open-source React applications. The main findings of the empirical evaluation indicate (a) the frequent occurrence of prop drillings across benchmark projects, irrespective of project size; (b) their generally low to moderate complexity in terms of data propagation depth, contrasted with the more prevalent complexity arising from the simultaneous forwarding of multiple properties along the same path; and, (c) the potential for automated elimination of a substantial share (76.3%) of prop drillings, primarily through refactoring to the Context API.
Transcript
Introduction to the show: ident: Computer Science. The day in computer science: software, systems and theory on arXiv.
Tom: We're looking at the paper: "Refactoring React Component Hierarchies to Eliminate Prop Drilling".
Jane: Here's the gist of the paper. In this work, we propose a static analysis method for identifying Prop Drilling instances in a React codebase and eliminating them using two automated refactoring strategies based on Context API and Component Composition, native React capabilities that facilitate the implementation of adaptable and reusable components The main findings of the empirical evaluation indicate (a) the frequent occurrence of prop drillings across benchmark projects, irrespective of project size (b) their generally low to moderate complexity in terms of data propagation depth, contrasted with the more prevalent complexity arising from the simultaneous forwarding of multiple properties along the same path and (c) the potential for automated elimination of a substantial share (76.3%) of prop drillings, primarily through refactoring to the Context API.
Tom: Prop Drilling Definition and Complexity Metrics The paper formally defines Prop Drilling based on Prop Passing and Prop Forwarding, where a sequence of prop passings constitutes a Prop Drilling from a source component to a target component The impact of Prop Drilling on code maintainability is affected by the number of intermediate components in Prop Drilling instances, which is assessed using the depth metric equal to the number of intermediates or equivalently to the number of prop forwardings in the prop drilling sequence Furthermore, Compound Prop Drilling (CPD) is defined by considering multiple properties simultaneously forwarded along the same path, where the cardinality of the property set J will be referred to as breadth of CP Ds,t,J.
Jane: Identification Method The identification of Prop Drilling instances is based on a graph representation of the React codebase called the Component Hierarchy Graph (CHG), which statically approximates parent-child relationships and data flow due to prop passings and prop forwardings This CHG construction involves static analysis of all production JS/TS files, where components are identified by analyzing the Abstract Syntax Tree (AST) representation of each source file The set of edges E in the CHG represents parent-child dependencies, and each edge is represented as a tuple (ca, cb, P Pa,b, P Fa,b), where P Pa,b and P Fa,b represent the sets of prop passings and prop forwardings from ca to cb respectively.
Tom: Prop Drilling instances are then identified through CHG traversal following sequences of compatible prop forwardings along successive edges to construct Prop Drilling instances Refactoring Strategies and Preconditions The paper specifies source code transformation procedures for eliminating a Prop Drilling instance through either refactoring strategy, namely Component Composition or the Context API The applicability of the Component Composition strategy is evaluated against a set of refactoring preconditions (RP1 to RP5), ensuring that the refactoring does not introduce syntax errors or alter external behavior If these are violated, the Context API strategy is evaluated against a separate set of preconditions (RP6 and RP7) For instance, RP5 states that given any intermediate component Ci in the prop drilling path, it should not declare and use in its implementation the predefined children property.
Paper summary: Jane: So to wrap up, the authors of "Refactoring React Component Hierarchies to Eliminate Prop Drilling" have put forward a method that uses a Component Hierarchy Graph and static analysis to find prop drilling instances.
Tom: They suggest two main refactoring paths—using the Context API or Component Composition—and their empirical results showed that these automated strategies can eliminate about seventy-six point three percent of all prop drillings identified in their benchmark projects <ref:2610.01376#pg1>.
Lu: The core idea they are pushing is that by understanding the depth and breadth metrics of data propagation, developers can use native React features to create more adaptable and reusable components <ref:2610.01376#pg3>.
Meng: What this means for us at the startup side is that we have a way to quantify the coupling introduced by prop drilling, which could be useful when deciding whether to refactor a specific piece of code or just leave it alone.
Lalam: And they also pointed out that while the method is powerful, its main limitation is that it relies on static analysis of the Abstract Syntax Tree, meaning it might not catch every dynamic data flow scenario <ref:2610.01376#pg3>.
Jane: So essentially, this paper provides a concrete framework for identifying and automating fixes for prop drilling in React codebases based on structural analysis and measurable complexity metrics <ref:2610.01376#pg1>.
Conclusion: Tom: So, to wrap up, this paper proposes a static analysis method to find prop drilling in React code and two refactoring strategies—Context API and Component Composition—to fix it <ref:2610.01376#pg1>.
Jane: It boils down to taking all that messy data passing between components, mapping it out on a graph, and then using those maps to automatically clean up the code by either moving data into the Context API or restructuring how components talk to each other <ref:2610.01376#pg4>.
Lu: The authors found that prop drilling is super common across different React projects, regardless of how big those projects are, and they also measured the complexity—they looked at depth and breadth—and it turns out compound prop drilling is actually way more frequent than just simple deep drilling <ref:2610.01376#pg2> to show up in the data flow.
Meng: So, when you look at the results, they found that this automated cleanup strategy can fix about seventy-six point three percent of all prop drillings they found across their benchmark projects <ref:2610.01376#pg2> which is a pretty solid number for a tool to handle automatically.
Tom: It shows the potential for this kind of analysis, but I'm looking at the authors themselves, Vangelis Gkinisa and Vassilis E. Zafeirisb <ref:2610.01376#pg2>. They are from Athens University of Economics and Business and Computer Science in Greece, right?
Jane: Yeah, they’ve got this method called ReactRefactor that lets you pick the refactoring strategy through an interactive command line menu <ref:2610.01376#pg1>, which is pretty cool because it gives you control over how you fix things.
Lu: What's interesting is they tested two different paths for refactoring—the Component Composition one and the Context API one—and they found that the Context API strategy could fix seventy-four point nine percent of all identified prop drillings <ref:2610.01376#pg2>.
Meng: That’s a big win for maintainability if you have to deal with hundreds of components; it means you can automate the bulk of the cleanup without manually hunting down every single data path <ref:2610.01376#pg2>.
Tom: It really suggests that using native React features like Context and Composition is a viable way to keep data flow organized, instead of just letting it become this tangled web <ref:2610.01376#pg3>.
Jane: And while they show what works with their benchmarks, I have to remember that static analysis can only see what’s written in the code right now, so it might miss some tricky dynamic data flows <ref:2610.01376#pg3>.
Lu: Exactly. Their method relies on building a Component Hierarchy Graph, which is a static approximation of how things are connected based on prop passings and forwardings <ref:2610.01376#pg4>, but it’s still just an approximation of the real-time behavior.
Meng: For us deploying models, that means this isn't a perfect safety net for runtime issues; you still need robust testing to catch what the static analyzer misses <ref:2610.01376#pg2>.
Tom: Anyway, it’s clear that by measuring depth and breadth, we can quantify the coupling introduced by prop drilling and use those numbers to make informed decisions about refactoring in our React apps.
More episodes
- 2505.16254-Human-AI Writing as Distributed Cognition: Reassessing Collaborative Writing Theories in the Age of LLMs
- 2506.10913-Choreographic Quick Changes: First-Class Location (Set) Polymorphism
- 2507.14812-A Black-Box Approach for Exogenous Replenishment in Online Resource Allocation
- 2507.15448-Frames over finite fields with respect to the Galois inner product and their connections to self-orthogonal and LCD codes
- 2508.21572-NewsReX: An Open-Source Multi-Framework for Neural News Recommendation
- 2509.17028-Impact of Packetization on Network Calculus Analysis
- 2510.17342-AoA Services in 5G Networks: A Framework for Real-World Implementation and Systematic Testing
- 2511.04088-Efficient and rate-optimal list-decoding in the presence of minimal feedback
- 2511.17264-Notes on Stack Machines and Quantum Stack Machines
- 2601.15318-On the closest balanced game