0

I have a sample Xstate state machine here: https://codesandbox.io/p/sandbox/divine-bird-3c9mpx

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",
        },
        "text.commit": {
          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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.