State Machine Pattern for UI Logic
Modeling a component's behavior as a finite set of distinct states and explicit transitions between them, instead of scattered boolean flags.
The state machine pattern models a system — often a UI component, but equally applicable to any process with distinct phases — as a finite set of named states (like idle, loading, success, error) along with explicit, well-defined transitions between them, rather than representing the same information as a scattered collection of independent boolean flags (isLoading, hasError, isSuccess) that can, if not carefully managed, end up in combinations that don't actually make logical sense (like isLoading and hasError both being true simultaneously). This pattern has become increasingly popular in frontend development specifically because UI components very naturally have a small number of mutually exclusive modes.
A state machine is like a well-designed vending machine's internal logic: it can only be in one specific mode at a time — waiting for coins, dispensing, out of stock — and it only accepts the specific inputs that are valid for its current mode, refusing to even consider a 'dispense' button press while it's still in 'waiting for coins' mode, rather than a poorly-designed machine that tracks a pile of independent switches that could theoretically all be flipped on at once, leading to nonsensical states nobody actually designed for.