Updates the current context of the machine.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/statelyai/xstate/llms.txt
Use this file to discover all available pages before exploring further.
Signature
Parameters
An object that represents the partial context to update, or a function that returns an object that represents the partial context to update.When provided as a function, it receives
AssignArgs containing:context- the current state contextevent- the event that triggered this actionspawn- a function to spawn child actorsself- reference to the current actorsystem- reference to the actor system
- A static value to assign
- A function that receives
AssignArgsand returns the value to assign
Returns
An action function that updates the machine’s context when executed.
Examples
Object assignment
Function assignment
Using spawn in assign
If
context is undefined in the machine config, assign will throw an error at runtime.