Learn how to use actions in XState.
Statecharts give you a great deal of control over running side effects in your app. The first method is through actions.
Along with the assign action, XState has several other built-in actions which can do different things in a state machine.