React + XState: How do we restart the state machine? #2108
Replies: 3 comments 8 replies
-
|
When referencing a state from the root, you can do it using a relative path -- So, something like this should work: const machine = createMachine({
id: "something",
context: {
val1: 1,
val2: 2
},
on: {
RESET: {
target: '.idle',
actions: assign(context => {
return {
val1: 1,
val2: 2,
}
})
}
},
initial: "idle",
states: {
idle: {
// ...
},
},
}) |
Beta Was this translation helpful? Give feedback.
-
|
The documentation states that calling https://xstate.js.org/docs/guides/interpretation.html#starting-and-stopping |
Beta Was this translation helpful? Give feedback.
-
|
Hey @jonathanstiansen did you find an answer to this? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey guys,
I'm using
useMachinehook - and I'd like to have a general button that resets the state back to the beginning.Things I've tried:
{on: {"RESET": 'firstNode'}}) outside of any specific state, that takes the machine back to the start (doesn't work)stateis immutable so that didn't workHow can I go about this?
(for 1 it I tried to add the line
{on: {'RESET': 'idle'}}Beta Was this translation helpful? Give feedback.
All reactions