Skip to content

Second argument for useMachine #994

Answered by segunadebayo
niksy asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @niksy,

The second argument to the useMachine hook can be used to sync/update the machine's context at runtime.

The first argument's context represents the "initial" context of the machine. It can't be updated afterward. In this case, the collection needs to be kept in sync so that keyboard navigation and value retrieval can work as expected.

For a static select component where the options are known ahead of time, the initial collection works just fine. In the case of dynamically changing items, then it needs to be kept in sync with the machine.

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by segunadebayo
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants