You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
useStateMachine is a curried function because TypeScript doesn't yet support [partial gerenics type inference](https://github.com/microsoft/TypeScript/issues/14400).
57
+
useStateMachine is a curried function because TypeScript doesn't yet support [partial generics type inference](https://github.com/microsoft/TypeScript/issues/14400).
58
58
This work around allows TypeScript developers to provide a custom type for the context while still having TypeScript infer all the types used in the configuration (Like the state & transitions names, etc...).
`useStateMachine` takes a JavaScript object as context (optional, see below) and one as the state machine configuration. It returns an array consisting of a `current state` object and a `transition` function.
69
69
70
-
**`current state`**
70
+
**state**
71
71
72
-
The `current state` consists of three properties: `value`, `nextEvents` and `context`.
72
+
The `state` consists of three properties: `value`, `nextEvents` and `context`.
73
73
74
74
`value` returns the name of the current state. `nextEvents` returns an array with the names of available transitions from this state.
75
75
76
-
**`transition`**
76
+
**transition**
77
77
78
78
`transition` takes a transition name as argument. If the transition exists and is allowed (see guard), it will change the state machine state and execute effects.
79
79
80
-
###State Machine configuration
80
+
## State Machine configuration
81
81
82
82
We'll pass the machine configuration as the second argument to useStateMachine:
For each state, you can define the possible transitions.
106
106
@@ -122,7 +122,7 @@ on: {
122
122
};
123
123
```
124
124
125
-
####Effects
125
+
### Effects
126
126
127
127
Uses the same format as useEffect: Effects are triggered when the state machine enters a given state. If you return a function from your effect, it will be invoked when leaving that state.
You can set up a guard per transition, using the transition object syntax. Guard run before actually running the transition: If the guard returns false the transition will be denied.
0 commit comments