Data in context can be:
initial
assigned by an action
const machine = Machine({
context: {
foo: 10,
bar: 50
},
states: {}
});
// or
const createMachine = (foo,bar) => Machine({
context: {
foo,
bar
},
states: {}
});
const machine = createMachine(10, 50)const countMachine = Machine({
context: {
count: 0,
},
states: {
ready: {
on: {
INCREMENT: {
actions: assign({
count: (context) => context.count + 1
})
}
}
}
}
});assign is special action from XState used to update the machine's context
on: {
INCREMENT: {
actions: assign({
// context will be an object with current value of `count: 0`
// event will be an object of type matching `INCREMENT`
count: (context, event) => context.count + 1
})
}
}