- Usage of many boolean flags in the code greatly increases complexity (Combinatorial explosion)
- The code is prone to errors and difficult to reason about & test
- There is no control over transitions between various states of the component
- State machine pattern can be useful to solve those problems
- There are many libraries that implement this pattern e.g.
There are several branches with the most important steps of the presentation:
- Start - Starting point with defined
useState
flags and no implementation - useState flags - Handle updates to
useState
flags - First state machine - Implement State machine (pure TypeScript)
- Refactor to XState - Use XState, remove boilerplate code
- Use context - Add XState context to track infinite state
- Use guards - Add XState guarded transition
- Combinatorial Explosion
- Implementing state machine library
- XState visualizer
- Statecharts: A visual formalism of complex systems
Based on a great tutorial by @mkczarkowski