liveBook · Manning

UML state diagram

As explained in React in Depth

A state diagram is a visual representation of states, transitions, and associated actions in a state machine.

A state diagram makes the legal flow of a complex operation visible by representing states as boxes and transitions as arrows. User-initiated and automatic transitions can be distinguished, while associated actions clarify what happens during each transition. section 8.7

Use the diagram to expose invalid paths before implementing them. In a list/detail interface, adding belongs only to list view, removing belongs only to detail view, and actions can differ by the current state. Contextual data, such as the current item or a retry count, lives above individual states and is updated as transitions occur. section 8.7.1 section 8.7

A practical modeling pass should:

  • Enumerate the meaningful states and the transitions available from each one. section 8.7
  • Remove transitions that the interface or business rules do not permit. section 8.7.1
  • Differentiate actions whose meaning changes with the current state, such as DO_THIS and DO_THAT. section 8.7.1
  • Attach transition actions to update contextual data, such as the selected item or a list of items. section 8.7.1

Signup flow

Model email and password entry, optional personal information, terms acceptance, and backward navigation as states and transitions. Keep a retry count in contextual data so a password can be rejected after three failed attempts without placing that business value inside one state. section 8.7

Figure 8.18 As the visitor must have a user to proceed on a given website, they can navigate the different states of the diagram, and in the end, they will be given access to the full website. States are boxes, and transitions are arrows. Only the arrows leading out from a given state are allowed transitions from that state. Fully drawn arrows are user-initiated transitions, and dashed arrows are automatic transitions based on various criteria.
figure

Use the state-flow figure to inspect boxes, outgoing arrows, user-initiated transitions, and automatic transitions before translating the model into application code. section 8.7

How React in Depth covers it

How deep it goes
Works through valid transitions, state-specific actions, and contextual data, but stops short of implementation code.
Examples
Uses signup navigation and a list/detail interface with constrained add, remove, do, and undo transitions.
What you can do after
Apply state diagrams to model permitted application flows and attach actions to transitions.
How it connects
Connects state machines, transitions, actions, contextual data, React, XState, and Stately.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of React in Depth. The section links point to the parts of the book it draws on.