Back to Playground
State Management

State Machines with XState

Predictable state management using finite state machines. Perfect for complex UI flows.

XStateReactTypeScript

Demo coming soon...

Code

const toggleMachine = createMachine({
  id: 'toggle',
  initial: 'inactive',
  states: {
    inactive: {
      on: { TOGGLE: 'active' }
    },
    active: {
      on: { TOGGLE: 'inactive' }
    }
  }
})

const Toggle = () => {
  const [state, send] = useMachine(toggleMachine)
  
  return (
    <button onClick={() => send('TOGGLE')}>
      {state.value}
    </button>
  )
}