Skip to content

Commit 7c5dbb6

Browse files
authored
Merge pull request #296 from audionerd/docs-migration-escalate
migration.mdx: `escalate` is removed
2 parents 0ea09dd + 9c477a0 commit 7c5dbb6

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

docs/migration.mdx

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,68 @@ actor.subscribe((state) => {
10181018
10191019
**Pre-migration tip:** Update v4 projects to track history using `actor.subscribe()`.
10201020
1021+
### Actions can throw errors without `escalate`
1022+
1023+
:::breakingchange
1024+
1025+
Breaking change
1026+
1027+
:::
1028+
1029+
The `escalate` action creator is removed. In XState v5 actions can throw errors, and they will propagate as expected. Errors can be handled using an `onError` transition.
1030+
1031+
<Tabs>
1032+
<TabItem value="v5" label="XState v5 beta">
1033+
1034+
```ts
1035+
//
1036+
const childMachine = createMachine({
1037+
// This will be sent to the parent machine that invokes this child
1038+
// highlight-start
1039+
entry: () => {
1040+
throw new Error('This is some error')
1041+
}
1042+
// highlight-end
1043+
});
1044+
1045+
const parentMachine = createMachine({
1046+
invoke: {
1047+
src: childMachine,
1048+
// highlight-start
1049+
onError: {
1050+
actions: ({ context, event }) => {
1051+
console.log(event.data);
1052+
// {
1053+
// type: ...,
1054+
// data: {
1055+
// message: 'This is some error'
1056+
// }
1057+
// }
1058+
}
1059+
}
1060+
// highlight-end
1061+
}
1062+
});
1063+
```
1064+
1065+
</TabItem>
1066+
1067+
<TabItem value="v4" label="XState v4">
1068+
1069+
```ts
1070+
// ❌ DEPRECATED
1071+
const childMachine = createMachine({
1072+
// highlight-start
1073+
entry: escalate('This is some error')
1074+
// highlight-end
1075+
});
1076+
1077+
/* ... */
1078+
```
1079+
1080+
</TabItem>
1081+
</Tabs>
1082+
10211083
## Actors
10221084
10231085
### Use actor logic creators for `invoke.src` instead of functions

0 commit comments

Comments
 (0)