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
Originally posted by dforer January 28, 2025
Hi, XState community!
I’ve been working on a project using XState v5 to handle state transitions in a simple state machine. I’m encountering a persistent issue where the params object sent with an event doesn’t seem to be passed to the actions during transitions.
Here’s what’s happening:
I send an event to the machine via actor.send() with a params property.
Example:
actor.send({ type: 'START', params: { additionalInfo: 'Logging START event' } });
The transition to the next state occurs correctly, and the action tied to the transition executes.
However, inside the action, the second argument (params) is consistently undefined.
Here’s a minimal example of the state machine:
consttestMachine=createMachine({id: 'simple',initial: 'idle',states: {idle: {on: {START: {target: 'running',actions: (context,params)=>{console.log('Transitioning from idle to running with params:',params||'No params received');},},},},running: {on: {STOP: {target: 'idle',actions: (context,params)=>{console.log('Transitioning from running to idle with params:',params||'No params received');},},},},},});
Here’s the output I’m seeing when I run this example:
Starting the state machine...
Actor received state: idle
Transitioned to state: idle
About to send START event...
Sending START event with: { type: 'START', params: { additionalInfo: 'Logging START event' } }
Transitioning from idle to running with params: No params received
Actor received state: running
Transitioned to state: running
Sent START event.
About to send STOP event...
Sending STOP event with: { type: 'STOP', params: { additionalInfo: 'Logging STOP event' } }
Transitioning from running to idle with params: No params received
Actor received state: idle
Transitioned to state: idle
Sent STOP event.
Expected Behavior
The params object sent with the event should be accessible in the second argument of the transition actions. For example:
Transitioning from idle to running with params: { "additionalInfo": "Logging START event" }
Questions
1. Is there something specific I need to do in XState v5 to ensure the params are passed to the actions during transitions?
2. Are there breaking changes in v5 related to how events and params are handled compared to v4?
Any guidance or suggestions would be greatly appreciated!
Thank you!
The text was updated successfully, but these errors were encountered:
Discussed in #5179
Originally posted by dforer January 28, 2025
Hi, XState community!
I’ve been working on a project using XState v5 to handle state transitions in a simple state machine. I’m encountering a persistent issue where the params object sent with an event doesn’t seem to be passed to the actions during transitions.
Here’s what’s happening:
Example:
actor.send({ type: 'START', params: { additionalInfo: 'Logging START event' } });
Here’s a minimal example of the state machine:
Here’s the output I’m seeing when I run this example:
Starting the state machine...
Actor received state: idle
Transitioned to state: idle
About to send START event...
Sending START event with: { type: 'START', params: { additionalInfo: 'Logging START event' } }
Transitioning from idle to running with params: No params received
Actor received state: running
Transitioned to state: running
Sent START event.
About to send STOP event...
Sending STOP event with: { type: 'STOP', params: { additionalInfo: 'Logging STOP event' } }
Transitioning from running to idle with params: No params received
Actor received state: idle
Transitioned to state: idle
Sent STOP event.
Expected Behavior
The params object sent with the event should be accessible in the second argument of the transition actions. For example:
Transitioning from idle to running with params: { "additionalInfo": "Logging START event" }
Questions
1. Is there something specific I need to do in XState v5 to ensure the params are passed to the actions during transitions?
2. Are there breaking changes in v5 related to how events and params are handled compared to v4?
Any guidance or suggestions would be greatly appreciated!
Thank you!
The text was updated successfully, but these errors were encountered: