Skip to content

Parent states

States can contain more states, also known as child states. These child states are only active when the parent state is active.

Child states are nested inside their parent states.

Video player state machine containing closed and opened states. On the Play event, the Closed state transitions to the Opened state. The Opened state invokes a startVideo actor and has a description of “The video player should be in full-screen mode.” The Opened state contains Playing and Paused states, which are transitioned between using the Pause and Play events. There’s a Stop event from the Opened state that transitions to the final state of Stopped. There’s a delayed transition from the Stopped state back to the Closed state after 5 seconds.Video player state machine containing closed and opened states. On the Play event, the Closed state transitions to the Opened state. The Opened state invokes a startVideo actor and has a description of “The video player should be in full-screen mode.” The Opened state contains Playing and Paused states, which are transitioned between using the Pause and Play events. There’s a Stop event from the Opened state that transitions to the final state of Stopped. There’s a delayed transition from the Stopped state back to the Closed state after 5 seconds.

View this machine in the Stately Studio.

In the video player above, the Opened state is a parent state to the PlayingPaused, and Stopped states. These states, their transitions, and their events are nested inside the Opened state.

Add a child state

First, select your machine or an existing state where you want to create the child state. Then…

  • Use the + State button that appears above the selected state to create a nested child state. Or…
  • If a state already contains child states, you can double-click inside the parent state to create another child state.

Change the parent state of a child state

Using the State details panel:

  1. Select the child state you want to reparent.
  2. Open the State details panel from the right tool menu.
  3. Choose your desired new parent from the Parent dropdown menu.