Packages

xstate

5.33.4 · 7 Nov 2026MIT9M / weekRepositoryHomepagenpmAtom feed

Your version

4.24.0

14 Sep 2021Where it was published

4.38.3 is the newest release of 4.x.

In short

3 new1 fixed

Release note

Minor Changes

  • You can now know if an event will cause a state change by using the new state.can(event) method, which will return true if an interpreted machine will "change" the state when sent the event, or false otherwise:

    const machine = createMachine({
      initial: 'inactive',
      states: {
        inactive: {
          on: {
            TOGGLE: 'active'
          }
        },
        active: {
          on: {
            DO_SOMETHING: { actions: ['something'] }
          }
        }
      }
    });
    
    const state = machine.initialState;
    
    state.can('TOGGLE'); // true
    state.can('DO_SOMETHING'); // false
    
    // Also takes in full event objects:
    state.can({
      type: 'DO_SOMETHING',
      data: 42
    }); // false

    A state is considered "changed" if any of the following are true:

    • its state.value changes

    • there are new state.actions to be executed

    • its state.context changes

    See state.changed (documentation) for more details.

Patch Changes

  • A regression was fixed where actions were being typed as never if events were specified in createModel(...) but not actions:

    const model = createModel(
      {},
      {
        events: {}
      }
    );
    
    model.createMachine({
      // These actions will cause TS to not compile
      entry: 'someAction',
      exit: { type: 'someObjectAction' }
    });

A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.