Skip to content

Commit

Permalink
Add changeset
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkpiano committed Aug 25, 2021
1 parent 658c287 commit a4cfce1
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .changeset/nice-pugs-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
'xstate': minor
---

You can now know if an event will cause a state change by using the new `state.can(event)` method, which will return `true` if the machine will change the state when sent the `event`, or `false` otherwise:

```js
const machine = createMachine({
initial: 'inactive',
states: {
inactive: {
on: {
TOGGLE: 'active'
}
},
active: {
on: {
DO_SOMETHING: { actions: ['something'] }
}
}
}
});

const state = machine.initialState;

state.can('TOGGLE'); // true
state.can('DO_SOMETHING'); // false

// Also takes in full event objects:
state.can({
type: 'DO_SOMETHING',
data: 42
}); // false
```

0 comments on commit a4cfce1

Please sign in to comment.