I want to execute an action in every state's entry. How can I do that?
It can be done like this:
const promiseMachine = createMachine({
id: "promise",
initial: "pending",
states: {
pending: {
entry: ["myAction"]
},
resolved: {
entry: ["myAction"]
},
rejected: {
entry: ["myAction"]
}
}
});
However, I have 10+ states, it becomes repetitive to write the same code over and over again.
Iterate config before creating machine.
For example