github statelyai/xstate @xstate/react@1.6.0

latest releases: @xstate/vue@4.0.0, @xstate/store@2.6.1, @xstate/svelte@4.0.0...
3 years ago

Minor Changes

  • 4b4872ca #2241 Thanks @mattpocock! - Changed the behaviour of guards, delays and activities when declared as options in useMachine/useInterpret.

    Previously, guards could not reference external props, because they would not be updated when the props changed. For instance:

    const Modal = props => {
      useMachine(modalMachine, {
        guards: {
          isModalOpen: () => props.isOpen
        }
      });
    };

    When the component is created, props.isOpen would be checked and evaluated to the initial value. But if the guard is evaluated at any other time, it will not respond to the props' changed value.

    This is not true of actions/services. This will work as expected:

    const Modal = props => {
      useMachine(modalMachine, {
        actions: {
          consoleLogModalOpen: () => {
            console.log(props.isOpen);
          }
        }
      });
    };

    This change brings guards and delays into line with actions and services.

    ⚠️ NOTE: Whenever possible, use data from within context rather than external data in your guards and delays.

Patch Changes

  • fe3e859f #2522 Thanks @farskid, @Andarist! - Fixed an issue with actors not being spawned correctly by useMachine and useInterpret when they were defined a lazily evaluated context, like for example here:

    createMachine({
      // lazy context
      context: () => ({
        ref: spawn(() => {})
      })
    });

Don't miss a new xstate release

NewReleases is sending notifications on new releases.