Skip to content

Commit ae704da

Browse files
committed
Add to migration
1 parent 4536532 commit ae704da

File tree

1 file changed

+42
-7
lines changed

1 file changed

+42
-7
lines changed

docs/migration.mdx

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -456,15 +456,15 @@ const machine = createMachine({
456456
</TabItem>
457457
</Tabs>
458458

459-
### Use `params` to pass custom event data
459+
### Use `params` to pass params to actions & guards
460460

461461
:::breakingchange
462462

463463
Breaking change
464464

465465
:::
466466

467-
Properties other than `type` on action objects and guard objects should be nested under a `params` property; `{ type: 'someType', message: 'hello' }` becomes `{ type: 'someType', params: { message: 'hello' }}`:
467+
Properties other than `type` on action objects and guard objects should be nested under a `params` property; `{ type: 'someType', message: 'hello' }` becomes `{ type: 'someType', params: { message: 'hello' }}`. These `params` are then passed to the 2nd argument of the action or guard implementation:
468468

469469
<Tabs>
470470
<TabItem value="v5" label="XState v5 beta">
@@ -478,6 +478,22 @@ const machine = createMachine({
478478
message: 'Hello world',
479479
},
480480
},
481+
on: {
482+
someEvent: {
483+
guard: { type: 'isGreaterThan', params: { value: 42 } },
484+
},
485+
},
486+
}).provide({
487+
actions: {
488+
greet: ({ context, event }, params) => {
489+
console.log(params.message); // 'Hello world'
490+
},
491+
},
492+
guards: {
493+
isGreaterThan: ({ context, event }, params) => {
494+
return event.value > params.value;
495+
},
496+
},
481497
});
482498
```
483499

@@ -487,12 +503,31 @@ const machine = createMachine({
487503

488504
```ts
489505
// ❌ DEPRECATED
490-
const machine = createMachine({
491-
entry: {
492-
type: 'greet',
493-
message: 'Hello world',
506+
const machine = createMachine(
507+
{
508+
entry: {
509+
type: 'greet',
510+
message: 'Hello world',
511+
},
512+
on: {
513+
someEvent: {
514+
cond: { type: 'isGreaterThan', value: 42 },
515+
},
516+
},
494517
},
495-
});
518+
{
519+
actions: {
520+
greet: (context, event, { action }) => {
521+
console.log(action.message); // 'Hello world'
522+
},
523+
},
524+
guards: {
525+
isGreaterThan: (context, event, { guard }) => {
526+
return event.value > guard.value;
527+
},
528+
},
529+
},
530+
);
496531
```
497532

498533
</TabItem>

0 commit comments

Comments
 (0)