XState 5.28.0

5.28.0
Added 1
  • Added routable states that can be navigated to from anywhere via xstate.route events, with support for guards to conditionally restrict navigation
Fixed 1
  • Export types so setup() declaration emit works
Minor Changes
  • #4184 a741fe7 Thanks @davidkpiano! - Added routable states. States with route: {} and an explicit id can be navigated to from anywhere via a single { type: 'xstate.route', to: '#id' } event.

    const machine = setup({}).createMachine({
      id: 'app',
      initial: 'home',
      states: {
        home: { id: 'home', route: {} },
        dashboard: {
          initial: 'overview',
          states: {
            overview: { id: 'overview', route: {} },
            settings: { id: 'settings', route: {} }
          }
        }
      }
    });
    
    const actor = createActor(machine).start();
    
    // Route directly to deeply nested state from anywhere
    actor.send({ type: 'xstate.route', to: '#settings' });
    

    Routes support guards for conditional navigation:

    settings: {
      id: 'settings',
      route: {
        guard: ({ context }) => context.role === 'admin'
      }
    }
    
Patch Changes
View original

Upgraded? How did it go?

Discussion