xstate
xstate copied to clipboard
[v5] Add `.stateNode` for actions and guards
The stateNode where an action or guard originates can now be read in the action or guard's provided implementation, or inline:
const machine = createMachine({
initial: 'idle',
states: {
idle: {
meta: { message: 'I am idle', enabled: true },
entry: ({ stateNode }) => {
stateNode.message; // 'I am idle'
},
on: {
someEvent: {
guard: ({ stateNode }) => {
return stateNode.enabled; // true
}
}
}
}
}
});
🦋 Changeset detected
Latest commit: c1d81a956831fad2469fd97fce54ea759d525bbd
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 1 package
| Name | Type |
|---|---|
| xstate | Minor |
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
This pull request is automatically built and testable in CodeSandbox.
To see build info of the built libraries, click here or the icon next to each commit SHA.
Latest deployment of this branch, based on commit c1d81a956831fad2469fd97fce54ea759d525bbd:
| Sandbox | Source |
|---|---|
| XState Example Template | Configuration |
| XState React Template | Configuration |