github statelyai/xstate @xstate/react@1.6.2

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

Patch Changes

  • #2736 2246ae051 Thanks @Andarist, @davidkpiano, @VanTanev! - The useSelector(...) hook now works as expected when the actor passed in changes. The hook will properly subscribe to the new actor and select the desired value. See #2702

  • #2685 469268d39 Thanks @farskid, @Andarist! - Fixed a regression with a development-only warning not being shown when a machine reference is updated during the hook lifecycle. This usually happens when machine options are dependent on external values and they're passed via withConfig.

    const machine = createMachine({
      initial: 'foo',
      context: { id: 1 },
      states: {
        foo: {
          on: {
            CHECK: {
              target: 'bar',
              cond: 'hasOverflown'
            }
          }
        },
        bar: {}
      }
    });
    
    const [id, setId] = useState(1);
    const [current, send] = useMachine(
      machine.withConfig({
        guards: {
          hasOverflown: () => id > 1 // id is a reference to an outside value
        }
      })
    );
    
    // later when id updates
    setId(2);
    // Now the reference passed to `useMachine` (the result of `machine.withConfig`) is updated but the interpreted machine stays the same. So the guard is still the previous one that got passed to the `useMachine` initially, and it closes over the stale `id`.

Don't miss a new xstate release

NewReleases is sending notifications on new releases.