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
The `invoke.data` property is removed. If you want to provide context to invoked actors, use `invoke.input`:
1071
+
1072
+
<Tabs>
1073
+
<TabItem value="v5" label="XState v5 beta">
1074
+
1075
+
```ts
1076
+
// ✅
1077
+
constmachine=createMachine({
1078
+
// ...
1079
+
invoke: {
1080
+
src: 'someActor',
1081
+
input: {
1082
+
value: 42,
1083
+
},
1084
+
},
1085
+
});
1086
+
1087
+
// The input must be consumed by the invoked actor:
1088
+
constsomeActor=createMachine({
1089
+
// ...
1090
+
context: ({ input }) =>input,
1091
+
});
1092
+
```
1093
+
1094
+
</TabItem>
1095
+
1096
+
<TabItem value="v4" label="XState v4">
1097
+
1098
+
```ts
1099
+
// ❌ DEPRECATED
1100
+
constmachine=createMachine({
1101
+
// ...
1102
+
invoke: {
1103
+
src: 'someActor',
1104
+
data: {
1105
+
value: 42,
1106
+
},
1107
+
},
1108
+
});
1109
+
```
1110
+
1111
+
</TabItem>
1112
+
</Tabs>
1113
+
1114
+
### Use `output` in final states instead of `data`
1115
+
1116
+
:::breakingchange
1117
+
1118
+
Breaking change
1119
+
1120
+
:::
1121
+
1122
+
To produce output data from a machine which reached its final state, use the `output` property instead of `data`:
1123
+
1124
+
1125
+
<Tabs>
1126
+
<TabItem value="v5" label="XState v5 beta">
1127
+
1128
+
```ts
1129
+
// ✅
1130
+
constmachine=createMachine({
1131
+
// ...
1132
+
states: {
1133
+
finished: {
1134
+
type: 'final',
1135
+
output: {
1136
+
answer: 42,
1137
+
},
1138
+
},
1139
+
},
1140
+
});
1141
+
```
1142
+
1143
+
</TabItem>
1144
+
1145
+
<TabItem value="v4" label="XState v4">
1146
+
1147
+
```ts
1148
+
// ❌ DEPRECATED
1149
+
constmachine=createMachine({
1150
+
// ...
1151
+
states: {
1152
+
finished: {
1153
+
type: 'final',
1154
+
data: {
1155
+
answer: 42,
1156
+
},
1157
+
},
1158
+
},
1159
+
});
1160
+
```
1161
+
1162
+
</TabItem>
1163
+
</Tabs>
1164
+
1165
+
### Don't use property mappers in `input` or `output`
1166
+
1167
+
:::breakingchange
1168
+
1169
+
Breaking change
1170
+
1171
+
:::
1172
+
1173
+
If you want to provide dynamic context to invoked actors, or produce dynamic output from final states, use a function instead of an object with property mappers.
1174
+
1175
+
<Tabs>
1176
+
<TabItem value="v5" label="XState v5 beta">
1177
+
1178
+
```ts
1179
+
// ✅
1180
+
constmachine=createMachine({
1181
+
// ...
1182
+
invoke: {
1183
+
src: 'someActor',
1184
+
input: ({ context, event }) => ({
1185
+
value: event.value,
1186
+
}),
1187
+
},
1188
+
});
1189
+
1190
+
// The input must be consumed by the invoked actor:
1191
+
constsomeActor=createMachine({
1192
+
// ...
1193
+
context: ({ input }) =>input,
1194
+
});
1195
+
1196
+
// Producing machine output
1197
+
constmachine=createMachine({
1198
+
// ...
1199
+
states: {
1200
+
finished: {
1201
+
type: 'final',
1202
+
output: ({ context, event }) => ({
1203
+
answer: context.value,
1204
+
}),
1205
+
},
1206
+
},
1207
+
});
1208
+
```
1209
+
1210
+
</TabItem>
1211
+
1212
+
<TabItem value="v4" label="XState v4">
1213
+
1214
+
```ts
1215
+
// ❌ DEPRECATED
1216
+
constmachine=createMachine({
1217
+
// ...
1218
+
invoke: {
1219
+
src: 'someActor',
1220
+
data: {
1221
+
value: (context, event) =>event.value, // a property mapper
1222
+
},
1223
+
},
1224
+
});
1225
+
1226
+
// Producing machine output
1227
+
constmachine=createMachine({
1228
+
// ...
1229
+
states: {
1230
+
finished: {
1231
+
type: 'final',
1232
+
data: {
1233
+
answer: (context, event) =>context.value, // a property mapper
1234
+
},
1235
+
},
1236
+
},
1237
+
});
1238
+
```
1239
+
1240
+
</TabItem>
1241
+
</Tabs>
1242
+
1062
1243
### Use `actors` property on `options` object instead of `services`
0 commit comments