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
版权声明:本文标题:Entry action is not working in case of Xstate machine from some non-initial state - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744023897a2577703.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论