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