As user interfaces become more dynamic, traditional code architectures based on dozens of boolean variables (`isHovered`, `isPressed`, `isSubmitting`, `isFailed`, `hasLoaded`) break down into unmaintainable spaghetti.
The problem with boolean flag explosion
If a UI component has 5 boolean flags, there are 2^5 = 32 theoretical states the component could find itself in. In reality, only 4 or 5 of those states make sense. When edge cases occur—such as a user clicking submit while an error toast is already dismissing—boolean logic often fails, displaying contradictory visuals or freezing controls.
How a finite state machine works in UI
A finite state machine (FSM) models a system with three core concepts:
1. **States:** The distinct modes a component can be in (e.g., Idle, Pressed, Validating, Success). The component can only ever be in exactly one state at a time.
2. **Inputs:** Values that code or users control, such as booleans, numbers, or triggers (e.g., `submitTrigger`, `progressPercentage`).
3. **Transitions:** The specific rules that move the component from one state to another when an input changes.
Better design-to-engineering collaboration
State machines provide a shared mental model that both designers and developers understand. Designers visually map out what happens on hover, drag, and error. Developers receive a clean state chart with clear inputs rather than vague design specs.
In ExodeUI, which we make, state machines are first-class citizens. You rig states, transitions, inputs, and spring timing directly on your vector layers, and the same state machine executes identically across React, Vue, SwiftUI, and Flutter.