xstate v5: a "before stop" action? #4801
-
I have two machines, A and B. A is the "root" machine. B is stateless and only sends & receives events. A spawns B in response to an event. In response to a later event, A stops B via Is it possible to configure B such that it executes a final action just before it is stopped--e.g., log that it is stopping? Would I need to add states to B to make something like this work? For example, send an event from A to B which causes B to enter a final state, then call I've tried adding an |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 11 replies
-
I suppose an |
Beta Was this translation helpful? Give feedback.
-
@davidkpiano @Andarist Regarding a potential It looks like |
Beta Was this translation helpful? Give feedback.
-
I was in same position, I'm looking to do all states and logic on xstate and avoid putting logic directly on react comopnents. This is not very pretty but I did manage move the cleanup logic from component back to xstate In the actions ...
actions: {
prepareCleanup: ({ self }) => {
const sub = self.subscribe({
complete: () => {
doCleanupStuff()
sub.unsubscribe()
},
})
},
},
...
entry: [{ type: 'prepareCleanup' }]
... |
Beta Was this translation helpful? Give feedback.
I suppose an
onStop: { … }
transition could be helpful here (cc. @Andarist)