Skip to content

Commit 6043ff3

Browse files
committed
docs(no-invalid-state-props): add docs about new state node props in xstate v5
1 parent ffa717e commit 6043ff3

File tree

1 file changed

+68
-2
lines changed

1 file changed

+68
-2
lines changed

docs/rules/no-invalid-state-props.md

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,20 @@ Certain properties accept specific values only:
1818
- `type` can be one of: "atomic", "compound", "parallel", "history", "final".
1919
- `history` can be one of: "shallow", "deep".
2020

21+
### XState v5
22+
23+
In XState v5 some props are no longer valid on state nodes:
24+
25+
- `activities`
26+
- `data`: removed in favor of a new prop `output`
27+
- `strict`
28+
- `schema`: removed in favor of a new prop `types`
29+
- `tsTypes`: removed in favor of a new prop `types`
30+
- `preserveActionOrder`
31+
- `predictableActionArguments`
32+
33+
If the above props are used with XState v5, this rule will report an error.
34+
2135
Examples of **incorrect** code for this rule:
2236

2337
```javascript
@@ -71,13 +85,61 @@ createMachine({
7185
Examples of **correct** code for this rule:
7286

7387
```javascript
74-
// ✅ all state props are valid
88+
// ✅ all state props are valid (XState v4)
7589
createMachine({
7690
id: 'root',
91+
strict: true,
7792
description: 'this is the main machine',
7893
predictableActionArguments: true,
94+
preserveActionOrder: true,
95+
tsTypes: {},
96+
schema: {},
97+
context: {}, // valid in the root node
98+
initial: 'idle',
99+
states: {
100+
idle: {
101+
type: 'parallel',
102+
entry: 'log',
103+
exit: 'log',
104+
always: [],
105+
after: {},
106+
states: {},
107+
onDone: {},
108+
on: {},
109+
tags: ['off'],
110+
activities: ['beeping'],
111+
},
112+
busy: {
113+
type: 'compound',
114+
initial: 'reading',
115+
states: {
116+
hist: {
117+
type: 'history',
118+
history: 'deep',
119+
target: 'writing',
120+
},
121+
reading: {
122+
meta: {
123+
value: 42,
124+
},
125+
},
126+
writing: {},
127+
},
128+
},
129+
done: {
130+
type: 'final',
131+
data: { answer: 42 },
132+
},
133+
},
134+
})
135+
136+
// ✅ all state props are valid (XState v5)
137+
createMachine({
138+
id: 'root',
139+
types: {},
140+
description: 'this is the main machine',
79141
context: {}, // valid in the root node
80-
initial: 'idle'
142+
initial: 'idle',
81143
states: {
82144
idle: {
83145
type: 'parallel',
@@ -107,6 +169,10 @@ createMachine({
107169
writing: {},
108170
},
109171
},
172+
done: {
173+
type: 'final',
174+
output: { answer: 42 },
175+
},
110176
},
111177
})
112178
```

0 commit comments

Comments
 (0)