---
title: "State Machines in Vue: A Union Type, One Function and a Tiny useReducer | VueDigest"
description: "This article discusses how to implement state machines in Vue using TypeScript, highlighting the limitations of using multiple refs for state management. It introduces a discriminated union to define states and a transition function to handle state changes, ultimately proposing a custom `useReducer` composable for managing state in a more structured way. The approach aims to eliminate bugs associated with handling multiple states and improve code clarity."
canonical_url: "https://vuedigest.com/news/state-machines-in-vue-a-union-type-one-function-and-a-tiny-usereducer"
last_updated: "2026-11-15T16:00:24.812Z"
meta:
  "og:description": "This article discusses how to implement state machines in Vue using TypeScript, highlighting the limitations of using multiple refs for state management. It introduces a discriminated union to define states and a transition function to handle state changes, ultimately proposing a custom `useReducer` composable for managing state in a more structured way. The approach aims to eliminate bugs associated with handling multiple states and improve code clarity."
  "og:image": "https://vuedigest.com/_og/d/c_Template.takumi%2Cdescription_~VGhpcyBhcnRpY2xlIGRpc2N1c3NlcyBob3cgdG8gaW1wbGVtZW50IHN0YXRlIG1hY2hpbmVzIGluIFZ1ZSB1c2luZyBUeXBlU2NyaXB0LCBoaWdobGlnaHRpbmcgdGhlIGxpbWl0YXRpb25zIG9mIHVzaW5nIG11bHRpcGxlIHJlZnMgZm9yIHN0YXRlIG1hbmFnZW1lbnQuIEl0IGludHJvZHVjZXMgYSBkaXNjcmltaW5hdGVkIHVuaW9uIHRvIGRlZmluZSBzdGF0ZXMgYW5kIGEgdHJhbnNpdGlvbiBmdW5jdGlvbiB0byBoYW5kbGUgc3RhdGUgY2hhbmdlcywgdWx0aW1hdGVseSBwcm9wb3NpbmcgYSBjdXN0b20gYHVzZVJlZHVjZXJgIGNvbXBvc2FibGUgZm9yIG1hbmFnaW5nIHN0YXRlIGluIGEgbW9yZSBzdHJ1Y3R1cmVkIHdheS4gVGhlIGFwcHJvYWNoIGFpbXMgdG8gZWxpbWluYXRlIGJ1Z3MgYXNzb2NpYXRlZCB3aXRoIGhhbmRsaW5nIG11bHRpcGxlIHN0YXRlcyBhbmQgaW1wcm92ZSBjb2RlIGNsYXJpdHku%2Ctitle_~U3RhdGUgTWFjaGluZXMgaW4gVnVlOiBBIFVuaW9uIFR5cGUsIE9uZSBGdW5jdGlvbiBhbmQgYSBUaW55IHVzZVJlZHVjZXI%2Cp_Ii9uZXdzL3N0YXRlLW1hY2hpbmVzLWluLXZ1ZS1hLXVuaW9uLXR5cGUtb25lLWZ1bmN0aW9uLWFuZC1hLXRpbnktdXNlcmVkdWNlciI%2Cs_5EReL83od6iedHbh.png"
  "og:image:height": "600"
  "og:image:type": image/png
  "og:image:width": "1200"
  "og:title": "State Machines in Vue: A Union Type, One Function and a Tiny useReducer"
  "twitter:description": "This article discusses how to implement state machines in Vue using TypeScript, highlighting the limitations of using multiple refs for state management. It introduces a discriminated union to define states and a transition function to handle state changes, ultimately proposing a custom `useReducer` composable for managing state in a more structured way. The approach aims to eliminate bugs associated with handling multiple states and improve code clarity."
  "twitter:image": "https://vuedigest.com/_og/d/c_Template.takumi%2Cdescription_~VGhpcyBhcnRpY2xlIGRpc2N1c3NlcyBob3cgdG8gaW1wbGVtZW50IHN0YXRlIG1hY2hpbmVzIGluIFZ1ZSB1c2luZyBUeXBlU2NyaXB0LCBoaWdobGlnaHRpbmcgdGhlIGxpbWl0YXRpb25zIG9mIHVzaW5nIG11bHRpcGxlIHJlZnMgZm9yIHN0YXRlIG1hbmFnZW1lbnQuIEl0IGludHJvZHVjZXMgYSBkaXNjcmltaW5hdGVkIHVuaW9uIHRvIGRlZmluZSBzdGF0ZXMgYW5kIGEgdHJhbnNpdGlvbiBmdW5jdGlvbiB0byBoYW5kbGUgc3RhdGUgY2hhbmdlcywgdWx0aW1hdGVseSBwcm9wb3NpbmcgYSBjdXN0b20gYHVzZVJlZHVjZXJgIGNvbXBvc2FibGUgZm9yIG1hbmFnaW5nIHN0YXRlIGluIGEgbW9yZSBzdHJ1Y3R1cmVkIHdheS4gVGhlIGFwcHJvYWNoIGFpbXMgdG8gZWxpbWluYXRlIGJ1Z3MgYXNzb2NpYXRlZCB3aXRoIGhhbmRsaW5nIG11bHRpcGxlIHN0YXRlcyBhbmQgaW1wcm92ZSBjb2RlIGNsYXJpdHku%2Ctitle_~U3RhdGUgTWFjaGluZXMgaW4gVnVlOiBBIFVuaW9uIFR5cGUsIE9uZSBGdW5jdGlvbiBhbmQgYSBUaW55IHVzZVJlZHVjZXI%2Cp_Ii9uZXdzL3N0YXRlLW1hY2hpbmVzLWluLXZ1ZS1hLXVuaW9uLXR5cGUtb25lLWZ1bmN0aW9uLWFuZC1hLXRpbnktdXNlcmVkdWNlciI%2Cs_5EReL83od6iedHbh.png"
  "twitter:title": "State Machines in Vue: A Union Type, One Function and a Tiny useReducer"
---

> Index of every page on this site: [llms.txt](https://vuedigest.com/llms.txt)

- [**a**** alexop.dev**](https://vuedigest.com/sources/alexopdev)
- November 15, 2026
- Article on alexop.dev

# **State Machines in Vue: A Union Type, One Function and a Tiny useReducer**

**Summary **

This article discusses how to implement state machines in Vue using TypeScript, highlighting the limitations of using multiple refs for state management. It introduces a discriminated union to define states and a transition function to handle state changes, ultimately proposing a custom \`useReducer\` composable for managing state in a more structured way. The approach aims to eliminate bugs associated with handling multiple states and improve code clarity.

![State Machines in Vue: A Union Type, One Function and a Tiny useReducer](https://alexop.dev/posts/state-machines-in-vue-a-union-type-one-function-and-a-tiny-use-reducer/index.png)

## **Related articles **

![What Is a CLI I, and What It Means to Build One](https://api.certificates.dev/storage/what-is-a-cli-i-and-what-it-means-to-build-one-1b2a51a07f.jpg)

Nov 17, 2026

## **What Is a CLI I, and What It Means to Build One**

**Certificates.dev**

![The Longest Line Of CSS?](https://i.ytimg.com/vi/W_kCmVnzvsk/maxresdefault.jpg)

Nov 11, 2026

## **The Longest Line Of CSS?**

**John Komarnicki**

![How to make Vue Dynamic Components more stable](https://media2.dev.to/dynamic/image/width=1200,height=627,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmf5ab4lpn5xofkbd90vv.png)

Nov 9, 2026

## **How to make Vue Dynamic Components more stable**

**Jakub Andrzejewski**

```json
{"@context":"https://schema.org","@graph":[{"@id":"https://vuedigest.com/#website","@type":"WebSite","description":"Your daily dose of Vue.js and Nuxt news. Curated articles, tutorials, and updates from the Vue ecosystem.","inLanguage":"en","name":"VueDigest","url":"https://vuedigest.com","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://vuedigest.com/news?search={search_term_string}"},"query-input":"required name=search_term_string"}],"publisher":{"@id":"https://vuedigest.com/#identity"}},{"@id":"https://vuedigest.com/news/state-machines-in-vue-a-union-type-one-function-and-a-tiny-usereducer#webpage","@type":"WebPage","dateModified":"2026-11-15T16:00:24.812Z","datePublished":"2026-11-15T00:00:00.000Z","description":"This article discusses how to implement state machines in Vue using TypeScript, highlighting the limitations of using multiple refs for state management. It introduces a discriminated union to define states and a transition function to handle state changes, ultimately proposing a custom `useReducer` composable for managing state in a more structured way. The approach aims to eliminate bugs associated with handling multiple states and improve code clarity.","name":"State Machines in Vue: A Union Type, One Function and a Tiny useReducer","url":"https://vuedigest.com/news/state-machines-in-vue-a-union-type-one-function-and-a-tiny-usereducer","breadcrumb":{"@id":"https://vuedigest.com/news/state-machines-in-vue-a-union-type-one-function-and-a-tiny-usereducer#breadcrumb"},"isPartOf":{"@id":"https://vuedigest.com/#website"},"potentialAction":[{"@type":"ReadAction","target":["https://vuedigest.com/news/state-machines-in-vue-a-union-type-one-function-and-a-tiny-usereducer"]}],"primaryImageOfPage":{"@id":"https://vuedigest.com/#logo"}},{"@id":"https://vuedigest.com/#identity","@type":"Organization","name":"VueDigest","url":"https://vuedigest.com","logo":{"@id":"https://vuedigest.com/#logo"}},{"@id":"https://vuedigest.com/news/state-machines-in-vue-a-union-type-one-function-and-a-tiny-usereducer#article","dateModified":"2026-11-15T16:00:24.812Z","datePublished":"2026-11-15T00:00:00.000Z","description":"This article discusses how to implement state machines in Vue using TypeScript, highlighting the limitations of using multiple refs for state management. It introduces a discriminated union to define states and a transition function to handle state changes, ultimately proposing a custom `useReducer` composable for managing state in a more structured way. The approach aims to eliminate bugs associated with handling multiple states and improve code clarity.","headline":"State Machines in Vue: A Union Type, One Function and a Tiny useReducer","inLanguage":"en","thumbnailUrl":"https://alexop.dev/posts/state-machines-in-vue-a-union-type-one-function-and-a-tiny-use-reducer/index.png","@type":["Article","NewsArticle"],"author":{"@id":"https://vuedigest.com/#identity"},"image":["https://alexop.dev/posts/state-machines-in-vue-a-union-type-one-function-and-a-tiny-use-reducer/index.png"],"isPartOf":{"@id":"https://vuedigest.com/news/state-machines-in-vue-a-union-type-one-function-and-a-tiny-usereducer#webpage"},"keywords":["vue","composition-api","tutorial","typescript","state-management"],"mainEntityOfPage":{"@id":"https://vuedigest.com/news/state-machines-in-vue-a-union-type-one-function-and-a-tiny-usereducer#webpage"},"publisher":{"@id":"https://vuedigest.com/#identity"}},{"@id":"https://vuedigest.com/news/state-machines-in-vue-a-union-type-one-function-and-a-tiny-usereducer#breadcrumb","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","item":"https://vuedigest.com/news","name":"Articles","position":1},{"@type":"ListItem","name":"State Machines in Vue: A Union Type, One Function and a Tiny useReducer","position":2}]},{"@id":"https://vuedigest.com/#logo","@type":"ImageObject","caption":"VueDigest","contentUrl":"https://mokkapps.twic.pics/vuedigest.com/logo.png","inLanguage":"en","url":"https://mokkapps.twic.pics/vuedigest.com/logo.png"}]}
```

## Sitemap

See the full [sitemap](https://vuedigest.com/sitemap.md) for all pages.
