React has become the most widely used web front-end framework, enabling the creation of graphical user interfaces in a declarative and compositional manner. Hooks are a set of APIs that manage side effects in function components in React. However, the...
React has become the most widely used web front-end framework, enabling the creation of graphical user interfaces in a declarative and compositional manner. Hooks are a set of APIs that manage side effects in function components in React. However, their semantics are often seen as opaque to developers, leading to UI bugs.
We introduce React-tRace, the first formal operational semantics of the essence of React Hooks. We demonstrate that our model captures the behavior of React, by theoretically showing that it embodies essential properties of Hooks and empirically comparing our React-tRace-definitional interpreter against a test suite. Furthermore, we showcase a practical visualization tool based on the formalization to demonstrate how developers can better understand the semantics of Hooks.