1. 9
    Use Internal Transitions in XState to Avoid State Exit and Re-Entry
    1m 25s

Use Internal Transitions in XState to Avoid State Exit and Re-Entry

Kyle Shevlin
InstructorKyle Shevlin

Share this video with your friends

Send Tweet

Transitions come in two varieties: "external" and "internal". By default, a transition is considered external. This means that a transition will exit the current state node, and enter the next state node (even if that state node is the state the machine is currently in). This exit/enter loop will trigger any actions that are set on the exit and entry properties.

A transition can be set to internal, either through setting a . (dot) in front of the state node name (as we do in this lesson), or through setting the property internal to true on the transition object.

When a transition is internal, it will not exit and enter the state node, which means that the actions in the exit/transition/entry loop will not be called.

Patrik Affentranger
Patrik Affentranger
~ a year ago

Would be good to highlight the benefit or use case for internal transitions?

Ian Jones
Ian Jones
~ a year ago

I asked this on Twitter and David gave me this reply:

It's just another way of specifying exactly which actions you want to be executed for a transition. It's one of those things that you'll know when you need it.

In general, prefer transition actions instead of entry/exit if you're concerned.