arXiv:2610.01376cs.SEOct 2026

Manuscript Offprint

arXiv:2610.01376

Refactoring React Component Hierarchies to Eliminate Prop Drilling

Vangelis Gkinis, Vassilis E. Zafeiris

Abstract

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 Node.js 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.

Keywords: React, Refactoring, Prop Drilling, Code smell, Component composition, Context API

1. Introduction

REACT is a library for implementing dynamic and interactive web user interfaces in JavaScript (JS) and TypeScript (TS) [1]. It supports modular and declarative development of front-end applications for the Web Browser platform. A REACT application implements the screens and the corresponding front-end logic of a web application. Each screen is structured in terms of web components

*Corresponding author. Address: University of Ioannina, 451 10, Ioannina, Greece.

Email addresses: vangelisgkinis1@gmail.com (Vangelis Gkinis), bzafiris@uoi.gr (Vassilis E. Zafeiris) or simply components, in REACT terminology, which encapsulate fragments of the screen presentation and behaviour. Components are implemented as functions or classes and declare their display view in JSX, a JS/TS extension with support for embedded XML-like markup syntax. REACT favors component composition and allows for specification of complex view structures in terms of hierarchically nested tags corresponding to standard HTML elements and elements representing other REACT components.

At runtime, the components comprising a screen are rendered to recursively generate a tree representation of the view structure, which is commonly referred to as Virtual DOM or render tree. Notice that, component rendering involves invocation of functional components or invocation of the render() method for class components. The Virtual DOM is, initially, constructed on page load, and the actual DOM is updated by harnessing content from host components, residing typically at the lower levels of the tree [2]. The arrival of events that update the UI state (e.g. user interactions, AJAX calls) trigger the generation of a new Virtual DOM through a process called reconciliation. During reconciliation the new Virtual DOM is constructed through traversal of the current Virtual DOM and re-rendering of components that require updates or reuse of unchanged portions of the tree. Changes between the current and the new Virtual DOM are, then, applied to the actual DOM (commit phase), minimizing, thus, costly DOM manipulations and improving performance.

On a technical basis, the reconciliation process is triggered by a state update, i.e. an update to the value of a component's state variable somewhere in the render tree. In case that multiple state updates occur within the same event handler, REACT batches them and typically performs a single reconciliation pass. State variables and their respective state update (or "setter") functions are declared at the component level, through appropriate REACT system calls, called REACT hooks. State variables are distinct from locally declared variables in that they retain their values across component re-renders. Separate copies of state variables are associated with each component position in the render tree.

State management is one of the most challenging aspects of REACT development, involving both the handling of state updates and the propagation of data across the component hierarchy. State update deals with the flow of data from external sources (e.g. user input, network requests) towards the render tree. Developers must decide where state should be maintained within the component hierarchy and how it should be structured to avoid unnecessary re-renders. On the other hand, data propagation concerns the flow of information within the render tree and occurs during the initial rendering of the application, as well as on subsequent re-renders. REACT follows a unidirectional data-flow model where higher-level components forward to descendant components data that are required for their rendering. A standard approach for data propagation employs component properties or props; a component receives the required data through value assignments to its props (prop passings) in the returned JSX of the parent component. In case that the data owner resides higher in the component hierarchy, data are forwarded through successive prop passings across intermediate components. REACT, also, provides the Context API that allows data to be shared across entire subtrees without explicitly passing properties through intermediate components.

The practice of propagating data through component properties across multiple levels of the component hierarchy is known as Prop Drilling. According to the official REACT documentation, Prop Drilling should be avoided where possible, in favor of alternatives, such as the Context API [3]. More recently, research on the maintainability of REACT codebases classifies Prop Drilling as a code smell due to the difficulty in tracing the origin and uses of forwarded property values, especially in large component hierarchies, and the tight coupling introduced among participating components [4, 5, 6].

In this work, we propose a static analysis method for identifying Prop Drilling instances and eliminating them using two automated refactoring strategies based on the Context API and Component Composition, native REACT capabilities that facilitate the implementation of adaptable and reusable components. The identification of prop drillings is based on a graph representation of the REACT codebase – the Component Hierarchy Graph (CHG) – that statically approximates the parent-child relationships among components and the flow of data due to prop passings and prop forwardings. A set of refactoring preconditions determine whether a Prop Drilling instance is refactorable and which refactoring strategies are applicable. Finally, we specify source code transformation procedures for eliminating a Prop Drilling instance through either refactoring strategy.

The proposed method has been implemented as a Node.js command line tool, REACTREFACTOR, that analyzes efficiently large REACT codebases and applies refactorings under user guidance. We employed REACTREFACTOR to empirically evaluate our method on a benchmark dataset of 15 open-source REACT projects, in terms of its applicability, effectiveness and practicality. Among the main findings of the empirically study are (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 due to 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.

To the best of our knowledge this is the first work that studies the automation of a large-scale refactoring in a REACT codebase. Moreover, it is among the few studies that investigate the prevalence of code smells in real-world REACT applications and the first to focus specifically on Prop Drilling. Thus, the main contributions of this paper are as follows:

  • a static analysis method for identifying and automatically eliminating Prop Drilling instances through refactoring,

  • an empirical study of the prevalence and complexity of prop drillings in real-world applications, as well as their potential for automated elimination through refactoring,

• an open-source implementation of the proposed method, REACTREFACTOR, for analyzing component hierarchies and refactoring prop drillings.

The rest of the paper is organized as follows. Section 2 presents related work and Section 3 provides a specification of the Prop Drilling code smell and its implications on code maintainability. Moreover, in Section 4, we specify our method for identifying and refactoring Prop Drilling instances in a REACT codebase. Section 5 presents the experimental setup and the results of our empirical study, while Section 6 discusses potential threats to its validity. Finally, the paper is concluded in Section 7.

References (31)