admin管理员组

文章数量:1356304

I have a sample Xstate state machine here:

For my usecase, I am starting state machine from a state given by user (not the initial state - rehydrating). But the entry function of that non-initial state is not triggering. I want to run that function without changing that state.

Am I doing anything wrong ? Any workaround or suggestion ? Below is the sample code:

import { createMachine, assign, interpret } from "xstate";

export const machine = createMachine({
  context: {},
  id: "simple machine",
  initial: "reading",
  states: {
    reading: {
      on: {
        "text.edit": {
          target: "editing",
        },
      },
    },
    editing: {
      entry: ["someFunction"]
      on: {
        "text.change": {
          target: "editing",
        },
        "textmit": {
          target: "reading",
        },
        "text.cancel": {
          target: "reading",
        },
      },
    },
  },
}).withConfig({
  actions: {
    someFunction: function (context, event) {
      console.log(`into someFunction`);
    },
  },
});

starting machine:

 const actor = interpret(machine);
 actor.start("editing"); // non initial state

本文标签: Entry action is not working in case of Xstate machine from some noninitial stateStack Overflow