Delays

        Delays are used for                            transitions

automatic

{
  states: {
    delayed: {
      after: {
        1000: {
          target: "done"
        }
      }
    },
    done: {
      type: "final"
    }
  }
} 

Delays are defined with special           property

after

Events can also be delayed

const machine = Machine({
  states: {
    init: {
      entry: send("DONE", {
        id: "delayedEvent",
        delay: 1000,
      }),
      on: {
        DONE: {
          target: "ready",
        },
      },
    },
    ready: {
      type: "final",
    },
  },
});

          is a special event creator from XState

send

Delays can be defined outside of the machine

const machine = Machine(
  {
    states: {
      ready: {
        after: {
          DELAY: {},
        },
      },
    },
  },
  {
    delays: {
      DELAY: 1000,
    },
  }
);

coding time!

9. Delays

By Kuba Skoneczny

9. Delays

  • 146