Skip to content
Compare
Choose a tag to compare
@github-actions github-actions released this 30 Aug 22:17
· 2738 commits to main since this release
8d7a02e

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(() => {})
      })
    });