State Transitions

Toggle

The simplest FSM โ€” two states, one event. The machine owns the transition logic: state off on TOGGLE โ†’ on, and vice versa. Actions attached to transitions update the context (toggle count) as a pure function. No if/else, no scattered mutation.

interactive demo
off
TOGGLE
on
toggled 0 time(s)
๐ŸŒ“ Theme switcher (light / dark)
โ–ถ Play / pause media controls
๐Ÿ”” Notification settings toggles
๐Ÿšฉ Feature flags with side-effects