You don’t need a library to create a UI that uses a state machine


You don’t need a library to create a UI that uses a state machine.

Recipe:

1. Create a list of potential statuses (loading, saving, submitted, errored, etc.)

2. Declare a variable called “status” that holds the current status.

3. Code your UI using the “status” variable.
Now that status is stored in one spot, your UI can’t get in an illogical state.

For example, with separate isLoading and isErrored state, they could both feasibly be true at the same time. That’s a bug.

A single status var assures an illogical status cannot occur.

View original on X