If you must have legacy code, you want it written in statecharts. We'll break down the mental models required for understanding unfamiliar UI code, and compare the maintenance costs with and without statecharts.
Make legacy code delightful with statecharts
From:

React Finland 2021