how to set context in machine with context input and assign actions #4795
-
Hi, hi, I want to pass context to my machine when i create it like this inside my hook: import bootMachine from "../fsm/bootMachine"
...
...
const { shouldUseAPI } = useAPI()
const service = createActor(bootMachine, {
input: {
shouldUseAPI // ie dynamic from hook so i need to pass it into my machine
},
}) and my machine has this which I'm using therefore for the initial context based on that input: context: ({ input }) => ({ status: LoadingState.NONE, shouldUseAPI: input?.shouldUseAPI }), but as soon as I run this on eg an invoke: {
src: "initialiseAPI",
onDone: {
target: "initialise_user",
},
onError: {
actions: assign({ status: LoadingState.ERROR }),
target: "initialise_api_error",
},
}, then my context's when I use a normal context without input it's fine, but then I can't dynamically set the initial value . so how do I combine thanks for any suggestions |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
If u could create a runnable repro of ur problem (like a codesandbox or stackblitz) then we could quickly fix your issue there. |
Beta Was this translation helpful? Give feedback.
sorry I was using both
createActor
(to get a service) but alsouseMachine
when I should only really have one of themthus causing a bunch of conflicts
this works fine:
https://codesandbox.io/p/devbox/great-sid-9n56pd
sorry about that!