# `BB.Command.SetState`
[🔗](https://github.com/beam-bots/bb/blob/main/lib/bb/command/set_state.ex#L5)

Reusable command handler for transitioning between operational states.

Use this handler to define simple state transition commands without
implementing a custom handler. The target state is specified in the
handler options.

## Usage

    commands do
      command :enter_recording do
        handler {BB.Command.SetState, to: :recording}
        allowed_states [:idle]
      end

      command :exit_recording do
        handler {BB.Command.SetState, to: :idle}
        allowed_states [:recording]
      end
    end

Then execute:

    {:ok, cmd} = MyRobot.enter_recording()
    {:ok, :recording} = BB.Command.await(cmd)
    BB.Robot.Runtime.state(MyRobot)  # => :recording

## Handler Options

- `:to` (required) - The target state to transition to. Must be defined
  in the robot's `states` section.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
