Composables
useStateMachine
A tiny typed finite-state-machine helper for open/closed/checked-style component state.
Advanced. Primitive-authoring utility from
@vyui/core — most app code never calls this directly.Overview
import { useStateMachine } from '@vyui/core'
const { state, dispatch } = useStateMachine('closed', {
closed: { open: 'open' },
open: { close: 'closed' },
})
dispatch('open') // state.value === 'open'
machine maps each state to the events it accepts and the state each event transitions to. dispatch(event) only transitions if the current state has that event defined, otherwise it's a no-op.
Returns
| Property | Type | Description |
|---|---|---|
state | Ref<keyof M> | The current state. |
dispatch | (event) => void | Transitions state per machine, or no-ops if the event isn't valid for the current state. |
When to use it
Used internally by primitives with open/closed/checked-style state.