reactjsxstatexstate-react

React Xstate spawn machine with machine options


Is there any way to pass machine options such as "guards" and "delays" to a spawned machine either through the "spawn" function on the parent machine or the "useActor" hook on the context property?


Solution

  • After a while, I find out about the "withConfig" method on the machine. You can use it like this.

    assign({
                machine: () => spawn(someMachine.withConfig({
                    guards: {
                      //...
                    },
                })),
            })