Skip to content

How can I initialize xstate context with component props? #562

Closed Answered by dai-shi
github0013 asked this question in Q&A
Discussion options

You must be logged in to vote

We just had some discussions recently in the closed PR #289.
So, if we need create a machine using component props, it means we need to create within the component lifecycle.

const Component = ({ props }) => {
  const machineAtomRef = useRef()
  if (!machineAtomRef) {
    machineAtomRef.current = atomWithMachine(...)
  }
  ...
}

I think we should create a codesandbox example for this.
Since you raised this discussion, would you be willing to help?

Replies: 2 comments 8 replies

Comment options

You must be logged in to vote
6 replies
@dai-shi
Comment options

@github0013
Comment options

@dai-shi
Comment options

@github0013
Comment options

@dai-shi
Comment options

Answer selected by github0013
Comment options

You must be logged in to vote
2 replies
@github0013
Comment options

@dai-shi
Comment options

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