Skip to content

How to initialize context with React hook #4798

Answered by davidkpiano
amypellegrini asked this question in Q&A
Discussion options

You must be logged in to vote

Hey, thanks!

Can you please share a full code example?

In general, input is used in context like this:

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

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@amypellegrini
Comment options

Answer selected by amypellegrini
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants