On the Expressive Power of Hook-Indexed State: Comprehending State in the React UI Library (Extended Version)
Toby Ueno, Ezra Cooper, Simon Fowler, Sam Lindley
Abstract
React is currently the most popular JavaScript library for front-end web development. It endows UI components with state via the useState construct, through a mechanism that we name hook-indexed state. However, React's implementation of hook-indexed state is both fragile and poorly understood. Programmers frequently experience unexpected behavior, and the benefits of programming in this paradigm are wholly unclear. We define λreacthook, a core calculus that captures the essence of hook-indexed state, and give it a type system to statically rule out unexpected behavior. We then translate λreacthook into a calculus λreactref based on ML-style references, and prove that this translation preserves typability and semantics, thus showing that hook-indexed state is expressible in terms of standard references. The translation is local and admits a compositional definition, but involves significant code duplication. As well as illuminating the essence of state in React, our observations can inform the design of future reactive programming systems.
Create a lesson
Related papers
On the Expressiveness of Asynchronous Processes with Nested Session Types (Extended Version)
Shared title terminology · Sjors Wortelboer, Dan Frumin, Jorge A. Pérez
Multi-language Program Logics (Extended Version)
Shared title terminology · Alexander Loitzl, Niklas Mück, Michael Sammler
Expressive power of one-shot control operators and coroutines
Shared title terminology · Kentaro Kobayashi, Yukiyoshi Kameyama
Beyond Locks and Thread IDs: Static Data Race Detection Off The Beaten Path (Extended Version)
Shared title terminology · Daniel Bund, Julian Erhard, Michael Petter et al.
Iris on Indirection Theory: Lightweight Higher-order Ghost State
Shared title terminology · Darius Foo, Viet-Anh Nguyen, Wei-Ngan Chin
More Powerful Constant Value Checking with SMT Solving
Shared title terminology · Jonas Mittnacht, Florian Lanzinger