Provide systemId
for invoked and spawned actors to make them available in the actor.system
registry.
Specifying a systemId
property within invoke
blocks, and within options passed as the second argument to spawn
calls, will make the actor available in the actor.system
registry.
The systemId
property is supported in XState version 5 and above.
Examples of incorrect code for this rule:
// ❌ missing systemId in an invoke block
createMachine({
states: {
playing: {
invoke: {
src: 'game',
},
},
},
})
// ❌ missing systemId in a spawn call
createMachine({
states: {
initializing: {
entry: assign({
gameRef: () => spawn(game),
}),
},
},
})
// ❌ invalid systemId value
createMachine({
states: {
playing: {
invoke: {
src: 'game',
system: [],
},
},
},
})
// ❌ duplicate systemIds
createMachine({
states: {
playing: {
invoke: {
src: 'game',
systemId: 'actor1',
},
entry: assign({
gameRef: () => spawn(game, { systemId: 'actor1' }),
}),
},
},
})
Examples of correct code for this rule:
// ✅
createMachine{{
states: {
playing: {
invoke: {
src: 'game',
systemId: 'actor1',
},
},
},
}}
// ✅
createMachine({
states: {
initializing: {
entry: assign({
gameRef: () => spawn(game, { systemId: 'actor1' }),
}),
},
},
})