How to initialize context with React hook #4798
-
Hi folks! I'm building a React Native app with React My question is how to define the initial context for a state machine from a React component? In v4 I used to do something like: const [state, send] = useMachine(myMachine, machineOptions); where in However this doesn't work with v5. I tried passing const [state, send] = useMachine(chordChartMachine, {
input: {
// ...context here
},
}); But this doesn't work either. I understand this is where How does this work? BTW: congrats on the release of v5! Nice work. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey, thanks! Can you please share a full code example? In general, const chordChartMachine = createMachine({
context: ({ input }) => ({
userName: input.name,
// ... other context properties
}),
// ...
});
// ...
const [state, send] = useMachine(chordChartMachine, {
input: { name: 'some name' }
}); See the docs for more information: https://stately.ai/docs/input |
Beta Was this translation helpful? Give feedback.
Hey, thanks!
Can you please share a full code example?
In general,
input
is used incontext
like this:See the docs for more information: https://stately.ai/docs/input