Skip to content

Assign function works inline but not in options:action #1500

Answered by Andarist
tomByrer asked this question in General
Discussion options

You must be logged in to vote

It works - you have just made a mistake. actions is a part of the second argument of the Machine/createMachine and not part of the first one. So your machine should look like this:

const radioGroup = Machine(
  {
    id: "radioGroup",
    initial: "emptied",
    context: {
      selected: "",
    },
    states: {
      emptied: {
        on: {
          SELECT: {
            target: "filled",
            actions: ["selecting"],
          },
        },
      },
      filled: {
        on: {
          SELECT: {
            actions: ["selecting"],
          },
        },
      },
    },
  },
  {
    actions: {
      selecting: assign((context, event) => ({
        selected: event.selected,

Replies: 1 comment 2 replies

Comment options

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

@tomByrer
Comment options

Answer selected by tomByrer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants