What is a State Machine?

State Machine

is a concept used for designing complex system

B

A

Every state machine has following parts:

  • states
  • events
  • initial state
  • transitions
  • final state

You can only be in one state at the time

Transitions happen only when events are allowed

Everything is transparent

Machine will never go out of defined bounds

  const { isLoading, error, data } = useQuery('repoData', () =>
     fetch('https://foo.bar/api').then(res =>
       res.json()
     )
   )

Multiple variables deciding about a state of the app?

Let a machine to decide in which state your app should be

How to use State Machines in web applications?

Xstate

brings State Machines to Javascript world

 

...and Typescript world

1. What is State Machine

By Kuba Skoneczny

1. What is State Machine

  • 249